0

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
  • 11
  • 1
  • 8

3 Answers3

2

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.

tim
  • 121
  • 3
  • tim 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 Jul 21 '16 at 18:55
  • and thats normal you will see the changes in every tutorial and I have also a backup file from the www.conf file I already check that and I am sure that php-fpm is running you will is that also my question where I post a short list of current running process – vTillmann Jul 21 '16 at 18:59
  • the main problem is I think 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 – vTillmann Jul 21 '16 at 19:01
  • And if I check the php-fpm log file everthing is fine – vTillmann Jul 21 '16 at 19:03
  • The 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. – tim Jul 21 '16 at 20:51
  • I could not found any similiar command like yours which I could run on Centos to check php-fpm syntax – vTillmann Jul 22 '16 at 14:04
  • a few months ago I set a similar server but that was php5.X (I think). With that version I don't get any problem only with php7 – vTillmann Jul 22 '16 at 14:06
0

Can you please post the first few lines from your /etc/nginx/nginx.conf file? They should specify a user that the nginx threads run as. Typically (on debian at least) it is:

user www-data;

or

user nginx;

That user, or a group that the user is in, would need permissions on the /var/www/html/mysite folder.

It would also be helpful if you could post the results of:

sudo nginx -t
eschipul
  • 31
  • 2
-1

If the user and folder permissions are fine then check if SElinux is disabled or not.

  • I set setenforce 0 – vTillmann Jul 21 '16 at 18:24
  • sestatus command would show the current Selinux status. Have you rebooted the machine after disabling it? Please try that too. – Azfar Ullah Khan Jul 21 '16 at 18:31
  • so 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 – vTillmann Jul 21 '16 at 18:35
  • I think reboot is necessary for the changes to take effect. Please reboot the centos machine and see if the problem persist. – Azfar Ullah Khan Jul 21 '16 at 18:38
  • `setenforce 0` change SELinux current mode to permissive (`setenforce [ Enforcing | Permissive | 1 | 0 ]`). – Federico Sierra Jul 21 '16 at 18:42
  • nano /etc/selinux/config SELINUX=disabled Try this please and reboot the server. – Azfar Ullah Khan Jul 21 '16 at 18:46
  • @AzfarUllahKhan if you run setenforce 0 it is not necessar but if you change the config file it is because then it is permantly in mode permissive. But restarting server and nginx don't help me the error is still available – vTillmann Jul 21 '16 at 18:47
  • @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 Jul 21 '16 at 18:49
  • @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 Jul 21 '16 at 19:02
  • 1
    Note for future readers disabling SELinux is never the correct solution. – user9517 Dec 28 '18 at 06:36