Permission Denied to PHP Files on Centos 7 with nginx
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.
Related videos on Youtube
vTillmann
Updated on September 18, 2022Comments
-
vTillmann over 1 year
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
-
vTillmann almost 8 yearsI set setenforce 0
-
Azfar Ullah Khan almost 8 yearssestatus command would show the current Selinux status. Have you rebooted the machine after disabling it? Please try that too.
-
vTillmann almost 8 yearsso I can tell you that first I only set setenforce 0 and check the sestaus and it tell me that the current mode is permissive but the in cofig it is enforcing so I decide to change th config file too and then I restart the server, nginx and php-fpm
-
Azfar Ullah Khan almost 8 yearsI think reboot is necessary for the changes to take effect. Please reboot the centos machine and see if the problem persist.
-
Federico Sierra almost 8 years
setenforce 0
change SELinux current mode to permissive (setenforce [ Enforcing | Permissive | 1 | 0 ]
). -
Azfar Ullah Khan almost 8 yearsnano /etc/selinux/config SELINUX=disabled Try this please and reboot the server.
-
vTillmann almost 8 years@AzfarUllahKhan please note that the 404 error is available if I try to run /open .php files there is no 404 error if I try it with .html files
-
vTillmann almost 8 yearstim I only change a few line not more the lines you could see in my qestion at the beginning listen = /var/run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx user = nginx group = nginx
-
vTillmann almost 8 years@AzfarUllahKhan I think the main problem is if I run ps aux | grep -i php70w-fpm I get the admin user gamba with privileges but if I check the current running process there is nginx you can the the result in my main question
-
vTillmann almost 8 yearsAnd if I check the php-fpm log file everthing is fine
-
tim almost 8 yearsThe result from
ps aux
is not the php-fpm process, but the ps process. It doesn't look like the php-fpm process is actually running. Which is why I think it's a configuration problem - these types of errors are not reported in the php logs or nginx logs, the only way that I've found is to run the fpm config script I mentioned above. -
vTillmann almost 8 yearsI could not found any similiar command like yours which I could run on Centos to check php-fpm syntax
-
user9517 over 5 yearsIt seems unlikely that after 2.5 years vTillmann will still be having this issue.
-
user9517 over 5 yearsNote for future readers disabling SELinux is never the correct solution.