Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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
    #location ~ \.php$ {
    #    proxy_pass;

    # pass the PHP scripts to FastCGI server listening on
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass;
    #    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_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_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.

share|improve this question

The config line:


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

share|improve this answer
yes, php5-fpm is listening on that port, what else could be happening? – Novato Nov 24 '13 at 21:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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