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?

Mr.Boon
  • 1,471
  • 4
  • 24
  • 43

5 Answers5

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;
}
gxx
  • 5,591
  • 2
  • 22
  • 42
mingalevme
  • 196
  • 3
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.

miog
  • 41
  • 1
  • 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. – Rodion Baskakov Feb 26 '15 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! – Teekin Oct 08 '22 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

Xosofox
  • 197
  • 2
  • 2
  • 8
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;
}
Hangchen Yu
  • 111
  • 2
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