4

I have installed nginx,php7.0-fpm and mysql on my ubuntu 16.04 server. Everything works fine however It doesn't load a setup page of phpmyadmin. Below is my phpmyadmin nginx block.

location /phpmyadmin {
        root /usr/share/;
            index index.php index.html index.htm;
            location ~ ^/phpmyadmin/(.+\.php)$ {
                try_files $uri =404;
                #fastcgi_pass 127.0.0.1:9000;   
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            include fastcgi_params;
            }
    }

Below are my nginx access logs

/usr/share# tail -f /var/log/nginx/access.log 
127.0.0.1 - - [15/Oct/2016:17:13:06 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:06 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:41 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:44 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:46 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:46 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:47 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:47 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:21:26 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:21:28 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"

I do not have anything in nginx error log. php7.0-fpm is also running normally below is the log extract of the same.

 tail -f /var/log/php7.0-fpm.log 
[15-Oct-2016 17:09:48] NOTICE: fpm is running, pid 17062
[15-Oct-2016 17:09:48] NOTICE: ready to handle connections
[15-Oct-2016 17:09:48] NOTICE: systemd monitor interval set to 10000ms
[15-Oct-2016 17:21:10] NOTICE: Terminating ...
[15-Oct-2016 17:21:10] NOTICE: exiting, bye-bye!
[15-Oct-2016 17:21:11] NOTICE: configuration file /etc/php/7.0/fpm/php-fpm.conf test is successful

[15-Oct-2016 17:21:11] NOTICE: fpm is running, pid 17297
[15-Oct-2016 17:21:11] NOTICE: ready to handle connections
[15-Oct-2016 17:21:11] NOTICE: systemd monitor interval set to 10000ms

I need expert advice on this as I tried to change php-fpm listen mode from localhost port 9000 to php.sock. Same can observed in phpmyadmin nginx block config.

Shailesh Sutar
  • 1,427
  • 4
  • 22
  • 40

1 Answers1

2

With the exception of the phpmyadmin addition, typically your /etc/nginx/sites-available/default file should look like so in order for it to process PHP:

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
  include snippets/fastcgi-php.conf;

  # With php-fpm (or other unix sockets):
  fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
  }

So when you open a .php file in your browser, this location directive will process .php files including the file fastcgi-php.conf and it will pass the php script to php7.0-fpm.

Immediately after making any changes to any Nginx configuration file, test the configuration file like so sudo nginx -t, if all is well you should see this output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Then type sudo service nginx reload

You can test it out by adding a ghi.php file that will contain this snippet:

<?php
phpinfo();
?>

You want to go to cd /var/www/html and from inside of there you can do sudo vim ghi.php

Then you go to your <server-ip-address>/ghi.php and if you don't see anything then your server is still not processing php.

Daniel
  • 179
  • 1
  • 2
  • 13