3

Background & Environment

I am attempting to deploy a Nginx server with PHP7.1-FPM, following the instructions here and here:

  • The server is Ubuntu 16.04
  • Nginx version is 1.13.3
  • PHP version is PHP 7.1.9-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep 2 2017 05:56:43) ( NTS )

I am fairly new to all this, so compared to a seasoned linux admin, I am still somewhat ignorant of what's what, but I know enough to handle the basics.

The Issue

When I browse to a URL with as inspired01.DOMAIN.com/application/ I get a blank page. There is no entry in the nginx error log.

When I browse to a URL such as inspired01.DOMAIN.com/application/index.php I get a 404 error.

Tried so far

I have attempted the suggestions in the stackoverflow post here. As far as I could tell, my configuration already has the suggested entries that people are saying fixed this problem for them.

I was not able to resolve the issue with those answers. As that post is a few years old, I am thinking perhaps requirements have changed since then.

My Nginx configuration

My nginx.conf is:

user inspired786;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 1024;
    multi_accept on;
}

http { 
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 25;
    types_hash_max_size 2048;
    server_tokens off;
    client_max_body_size 64m;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    gzip_proxied any;
    gzip_comp_level 2;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    # Virtual Host Configs

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 444;
    }
}

The site's conf file is:

server {
    listen 80;
    listen [::]:80;

    server_name inspired01.DOMAIN.com;

    access_log /home/inspired786/DOMAIN.com/logs/access.log;
    error_log /home/inspired786/DOMAIN.com/logs/error.log;

    root /home/inspired786/DOMAIN.com/public/;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

Logs

No entry is generated in the Nginx server or site log.

No relevant entry is recorded to the FPM log at /var/log/php7.1-fpm.log

Question

I would like to know if there is anything obvious missing or wrong in this configuration, which would potentially result in php files not being parsed.

UPDATE

As per comment below, pasting here so anyone new sees it:

I enabled debug_connection and went through the masses of log output that produced. As far as I could tell, there were no issues being reported. Well, no obvious errors or warnings. So I created a basic hello.php file including a basic echo command, and also phpinfo. The file worked fine. So I suspect the issue is something else. Continuing to investigate.

Consider this question on hold for now, whilst I look into some other possibilities for the blank pages issue.

inspirednz
  • 4,807
  • 3
  • 22
  • 30
  • Look in the FPM logs and/or at least the nginx logs – Cody Caughlan Sep 24 '17 at 22:16
  • There's nothing related showing up in the logs. I've updated the question to clarify this (re Nginx log) and added info re FPM log. – inspirednz Sep 24 '17 at 22:25
  • http://nginx.org/en/docs/ngx_core_module.html#debug_connection – Deadooshka Sep 24 '17 at 22:28
  • I enabled `debug_connection` and went through the masses of log output that produced. As far as I could tell, there were no issues being reported. Well, no obvious `errors` or `warnings`. So I created a basic `hello.php` file including a basic echo command, and also phpinfo. The file worked fine. So I suspect the issue is something else. Continuing to investigate. – inspirednz Sep 24 '17 at 22:52
  • Blank page is often a PHP error. PHP errors can be logged to `nginx` (it used to be the default on some platforms), but `phpinfo` should tell you what your `error_log` settings are. You probably need to log PHP errors to get to the bottom of this problem. – Richard Smith Sep 25 '17 at 08:18
  • Thanks guys. Digging around, I've solved the issue. After setting up the VM I migrated a root folder from another server. It included a Wordpress installation, and numerous other PHP applications. It looks like the issue was not server related, but simply the various applications (including WP) having issues in the new environment. I've managed to iron most of them out. HOW DO I MARK A QUESTION AS SOLVED when there's really no answer, per se? – inspirednz Sep 26 '17 at 00:28

2 Answers2

0

I run on Linux 2.6, PHP5 and nginx my PHP file was shown as text

After many test i change the default file in C:\username\etc\nginx\sites-enabled as follow:

location ~ [^/]\.php(/|$) {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi_params;
  # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  # With php5-cgi alone:
  fastcgi_pass 127.0.0.1:9000;
  # With php5-fpm:
  #fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

After restart of nginx and PHP services PHP started working!

Check also if yours php files are under root path set in the default file and begin tests with a test.php file as follow:

<?php
/* test.php */
  phpinfo();
?>
Sebyddd
  • 4,305
  • 2
  • 39
  • 43
Gio Italy
  • 91
  • 1
  • 6
0

Try to fix permissions in your project directory. In Linux this worked for me:

sudo chown -R www-data:www-data .
askepott
  • 250
  • 3
  • 13