0

Installing this on a fresh Amazon AWS micro instance with Amazon Linux. I've installed nginx and php7. I can't seem to get php to load.

sudo yum install nginx
sudo yum install php70-fpm

Created a document root at:

/var/www/html

User/Group is nginx:nginx

Edit php-fpm conf to point to correct user/group:

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

user = nginx
group = nginx

listen.owner = nginx
listen.group = nginx
listen.mode = 0664

listen = /var/run/php-fpm/php-fpm.sock

Then I changed the default nginx conf

/etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    include /etc/nginx/conf.d/*.conf;

    index   index.php index.html index.htm;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        root         /var/www/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        location ~ \.php$ {
            fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }


    }

}

If I create a php file at document root I just get a 404. Any html page loads fine. Nothing is in my error.log for nginx or php.

1

Finally found the solution. I was blind, this was in the error.log after all. Because I'm using sockets in the configuration:

fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

I missed another file that required the proper setting:

/etc/nginx/conf.d/php-fpm.conf-7.0

upstream php-fpm {
        server 127.0.0.1:9000;
}

Change to:

upstream php-fpm {
        server unix:/var/run/php-fpm/php-fpm.sock;
}
  • tried but not working for me – Ashish Karpe Sep 15 '17 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.