1

I just've downloaded nginx 1.4 and right away I see the "Welcome to nginx!" message, then I've installed php5-fpm from the repositories so I create a php file at /usr/share/nginx/html/demo.php just with <?php echo "Hello World"; ?> inside.

(I'm trying under ElementaryOS Ubuntu 12.04 based) and followed this manual: http://wiki.nginx.org/PHPFcgiExample

Then when I visit http://localhost/demo.php it doesn't work, I give a 404 error. This is my /etc/nginx/conf.d/default.conf file:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

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

    #error_page  404              /404.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;
    #}
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

I thought that was a permissions issue, so I just change the user nginx to user www-data wich is the same user that fpm use (according to the conf file). Then I applied chown -R www-data:www-data /usr/share/nginx/html/ but I have same error.

I was looking for simmilar problems, I read that:

root   /usr/share/nginx/html;
index  index.html index.htm;

They need to be at server level (not local /), if I do that I get a blank page, but nothing else. Analyzing the headers I get an 200 Ok response.

If I use the default php snnipet instead of the one in the manuals:

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;
}

I give a 404 error but only in a blank page and the message "File not found." this rendered page is different from the one that I get earlier. I think this one comes from fpm and the other from nginx (Of course.. I'm not sure).

At the last I did chmod 777 /usr/share/nginx/html/demo.php and now it downloads the script, downloads the file demo.php to my pc.

So I want to know, how I can execute a PHP script with nginx + php5-fpm. I don't mind removing and purge the nginx, the fpm or the php packages, I just want to execute a php script in the webserver.

Thanks in advance. Have a good day.

1 Answer 1

0

The config line:

    fastcgi_pass 127.0.0.1:9000;

Is directing nginx to forward the request to a process listening on localhost port 9000. Do you have anything listening?

1
  • yes, php5-fpm is listening on that port, what else could be happening?
    – Novato
    Nov 24, 2013 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.