9

i just installed nginx 1.1.13 and php 5.4.0 on a centos 5.8 final 64bit machine. Nginx and PHP/Fpm are running, and I can run php scripts via ssh command line, but in the browser I keep getting 'File not found.' errors on all my PHP files.

This is how I have my nginx.conf handle PHP scripts:

 location ~ \.php$ { root /opt/nginx/html; fastcgi_pass unix:/tmp/fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name; include fastcgi_params; } 

This is a direct copy/paste from my other servers, where it works fine with this setup (but they run older versions of php/fpm).

Why am I getting those errors?

1
  • 1
    Never mind, it's sorted. It was a silly permissions issue. Commented Mar 11, 2012 at 12:44

5 Answers 5

18

Put "include fastcgi_params;" before all "fastcgi_param *" lines, "include fastcgi_params;" overrides all you "fastcgi_param *" lines (see nginx debug log):

location ~ \.php$ { root /opt/nginx/html; fastcgi_pass unix:/tmp/fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name; } 
3
  • 3
    Man, I've wasted 4 hours on it and your answer helped me. Commented Oct 21, 2012 at 8:03
  • I have tried to overcome this problem since yesterday. Your answer helped me very much! Thank you!!! Commented May 2, 2014 at 13:44
  • 1
    how do we do this without hardcoding the path ? $document_root vars seems to be not wokring ? Commented Jul 20, 2015 at 10:01
4

I had the same issue.

What I did to solve this was to check the user running nginx, php-fpm and check their permissions for accessing the folder where the root is. It is be default 'www-data'.

but you can find out by using the ps aux | grep php-fpm and ps aux | grep nginx commands.

You have to make sure the folder is accessible to the user running these processes.

2
  • Thank you for the clue. I tried to host my projects deep inside my Dropbox directory, which had 700 permissions by default. Changing Dropbox permission to 755 solved the issue. Commented Feb 26, 2015 at 22:31
  • This was my problem as well. I was restarting nginx after adding www-data to the proper group, but forgot to restart php8.1-fpm. Thanks! Commented Oct 8, 2022 at 19:55
1

I had the same issue, and for me it was a misconfigure/non-existing "root" directive in the nginx server config

1

I use such configuration, wish it could help you. It works in OS X. As for me, @Xosofox 's answer worked. I mistyped the version of nginx 1.6.2 as 1.2.6, so that the root became a non-existing directory.

location ~ \.php$ { fastcgi_intercept_errors on; root /usr/local/Cellar/nginx/1.6.2/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/local/Cellar/nginx/1.6.2/html$fastcgi_script_name; } 
0

I solve this problem by changing user and group tho the current user:group in php-fpm.d/www.conf

By default the user and group is 'nginx', change this....

Hope this helps

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.