Nginx – Permission Denied to PHP Files on Centos 7 with nginx

centos7nginxPHPphp-fpm

I have problem

WHAT I DID

Install Centos 7.2 with nginx 1.10
-- create a nginx server block sudo mkdir -p /var/www/example.com/html
-- set permission sudo chown -R nginx:nginx /var/www/example.com/html
--sudo chmod -R 755 /var/www
set setenforce 0
Install PHP7 and PHP-FPM
--change cgi.fix_pathinfo=1 to cgi.fix_pathinfo=0
-- and change in www.conf like 
    listen = /var/run/php-fpm/php-fpm.sock
    listen.owner = nginx 
    listen.group = nginx
    user = nginx 
    group = nginx

so if I create a index.html file in /var/www/example.com/html with a standard hello and open in in my browser I can see it now if I do the same with a php file thats but I get a 404 error

I know you would like to see the nginx example.com.conf file:

server {
listen 80;
server_name example.com www.example.com;

location / {
    root /var/www/example.com/html;
    index index.php index.html index.htm;
    try_files $uri $uri/ =404;
}
 ....
location ~ \.php$ {
    try_files $uri =404;
    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;
}

}

I don't forgot to restart nginx and php-fpm.
And also do not forgot to check the folder permissions form /var/www/example.com/html and all parents

Please do not put on hold as unclear or possible duplicate AND READ MORE

Whats my Problem

My Problem is that I cannot open the .php files

But I noticed that if I run

ps aux | grep -i php70w-fpm
gamba* 11458 0.0 0.0 112648 1004 pts/0 S+ 16:11 0:00 grep --color=auto -i php70w-fpm

*gamba is the user as admin (with root privileges to act with sudo).
But a few lines above you could see how my www.conf files looks like so

if I run

top

I get

11288 gamba 20 0 140904 2404 1148 S 0.0 0.0 0:01.00 sshd
11331 root 20 0 47788 1204 232 S 0.0 0.0 0:00.00 nginx
11332 nginx 20 0 48304 2220 828 S 0.0 0.0 0:00.01 nginx
12660 root 20 0 405024 13580 7532 S 0.0 0.1 0:00.03 php-fpm
12662 nginx 20 0 405024 7060 1004 S 0.0 0.0 0:00.00 php-fpm
12663 nginx 20 0 405024 7056 1004 S 0.0 0.0 0:00.00 php-fpm
12664 nginx 20 0 405024 7056 1004 S 0.0 0.0 0:00.00 php-fpm
12665 nginx 20 0 405024 7056 1004 S 0.0 0.0 0:00.00 php-fpm
12666 nginx 20 0 405024 7056 1004 S 0.0 0.0 0:00.00 php-fpm
12679 gamba 20 0 157828 2456 1560 R 0.0 0.0 0:02.05 top

So again my Problem is I cannot run .php files and I don't know what I have to do now to get that work I already have done really enought and check the logs and so on

Update

I forgot to give to the logs from nginx

 2016/07/21 15:22:37 [error] 11332#11332: *5 "/var/www/example.com/html/index.php" is forbidden (13: Permission denied), client: XX.XXX.XXX.XXX, server: example.com, request: "GET / HTTP/1.1", host: "example.com"

I have updated the nginx logs that whats an old error

Best Answer

Check to make sure your php config doesn't have any syntax errors or permissions problems - I'm not familiar with Centos7 but in Ubuntu 14.04 it's sudo /usr/sbin/php-fpm7.0 --fpm-config /etc/php/7.0/fpm/php-fpm.conf

that will tell you if there are any errors. When I've ran into this problem in the past, it was because the directory PHP-FPM was trying to write the PID file to didn't exist.