3

I am trying to setup up Nginx and php 7 on ubuntu 16.0 , prior to this I have only worked with WAMP on windows , I have successfully installed nginx and php , when i run this command on the terminal :

curl -I -v http://localhost/

It shows that the nginx server is ok, but it is not serving PHP files , been trying to figure this out for almost a day to know avail , I have searched similar questions on this site and all over the internet nothing seems to be helpful, here is what my configuration file looks like :

# Default server configuration
#
server {
  listen 80 default_server;
  listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

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

server_name 127.0.0.1:80;

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

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#   include snippets/fastcgi-php.conf;
#
#   # With php7.0-cgi alone:
#   fastcgi_pass 127.0.0.1:9000;
#   # With php7.0-fpm:
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  fastcgi_index index.php;
    include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#   deny all;
#}
}


 #server {
 #  listen 80;
 #  listen [::]:80;
 #
 #  server_name example.com;
 #
 #  root /var/www/example.com;
 #  index index.html;
 #
 #  location / {
 #      try_files $uri $uri/ =404;
 #  }
 #}

Any help render will be well appreciated , regards.

ebuoe
  • 31
  • 1
  • 3
  • Please update your question with details on 1) what happens when you browse to a php file 2) error logs from nginx and php-fpm and 3) php-fpm configuration. – EEAA Apr 03 '17 at 22:02
  • Check that the "sock" file exists, and that permissions are set appropriately. Maybe something like this http://stackoverflow.com/questions/23443398/nginx-error-connect-to-php5-fpm-sock-failed-13-permission-denied – Tim Apr 04 '17 at 01:25

2 Answers2

2

check if php7.0-fpm service is running.
systemctl list-units 'php*' the result is active and running when php-fpm is good status. if you find php7.0-fpm was not running, enable it.
systemctl list-units 'php*' and check again.

and then, try
curl -v 'http://localhost/index.php' if you can get php result, you will be check try_files directive in location / block.

minish
  • 656
  • 3
  • 12
0

Two reasons.

  1. Your php7.0-fpm might not be working. check its status.
  2. You are passing all php extension files to fastcgi_pass unix:/run/php/php7.0-fpm.sock; i.e. a temporary created socket. May be you php7.0-fpm is running on different socket. Although it is default port still i will ask you to check your configuration of listening port and user group over here. You could find the configuration of php7-fpm in

    /etc/php/7.0/fpm/pool.d/www.conf

Still in trouble Refer to this article