Nginx – php pages in a nginx + php-fpm server doesn’t load

nginxPHPphp-fpmphp53

I've installed a nginx server and php-fpm in a CentOS 6 system (hosted in Amazon EC2) with the following this instructions:

http://emka.web.id/linux/centos-linux/2011/installing-nginx-with-php-and-php-fpm/

A static html (index.html) loads when I go to my public DNS provided by Amazon, so the nginx works, but when i try to load a php page in the same directory as "index.php or hello.php" a error page displays this message: "The page you are looking for is temporarily unavailable. Please try again later."
When I run php-fpm without parameters and try again to load a php page, doesn't send me that page, but instead display a text message: "No input file specified".

The default directory where are the files is /usr/share/nginx/html

I think something is wrong with my configuration, but I don't know if is in php or nginx conf files. A few lines in /etc/nginx/nginx.conf which I think is the most relevant:

     #
    # The default server
    #
    server {
        listen       80;
        server_name  _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        error_page  404              /404.html;
        location = /404.html { 
root   /usr/share/nginx/html;
        }
# redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

By the way, all instalation operations and "nginx start" and "php-fpm" were made by root, because I can only access through SSH with that superuser. I don't know is related with my problem, but I know is recommended to use a normal user with sudo.

Best Answer

  • Firstly, you have different root in location / and location ~ \.php$
  • Secondly, do not hardcode the path value for SCRIPT_FILENAME.

"No input file specified" means that PHP cannot find the file which Nginx is telling it to look for. So, define the SCRIPT_FILENAME in fastcgi_params:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

(or include fastcgi.conf instead)

and change your PHP location to something like this:

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi_params;
    }

it would works.