Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to get nginx to run with PHP on my ubuntu staging server. Nginx by itself is working like a charm with static *.html-files, but any PHP file called by the browser outputs the code as plain text, which undoubtedly means that PHP isnt working properly. I am calling http://192.168.1.100/test.php which outputs the content of test.php inside the /var/www folder.

I've tried various solutions, but followed this guide as the main way of getting nginx to work, which it currently isn't with PHP files as mentioned.

My /etc/nginx/sites-enabled/default looks as below:

server {

        listen   80; ## listen for ipv4
        listen   [::]:80 default ipv6only=on; ## listen for ipv6
        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
                root   /var/www;
                index  index.html index.htm index.php;
                allow all;
        }

        location ~ .php$ {
          fastcgi_pass   127.0.0.1:9000;  # By all means use a different server$
          fastcgi_index  index.php;

          fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;   # !! $
          fastcgi_param  QUERY_STRING     $query_string;
          fastcgi_param  REQUEST_METHOD   $request_method;
          fastcgi_param  CONTENT_TYPE     $content_type;
          fastcgi_param  CONTENT_LENGTH   $content_length;
        }


}

Running netstat -plan | grep :9000 outputs tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1352/php5-cgi so apparently PHP is running.

What am I doing wrong and what should be changed to get it working?

share|improve this question
    
Your problem is not in the config you posted. Please provide the full config file and a sample URI which isn't working. –  Martin Fjordvald Mar 14 '11 at 11:25
    
Martin: Updated. Thanks for your help! –  Industrial Mar 14 '11 at 11:50
add comment

1 Answer

up vote 0 down vote accepted

I have no idea on what went wrong. I reset the VPS to the fresh install image, tried a completely different tutorial, http://www.howtoforge.com/installing-nginx-with-php5-and-php-fpm-and-mysql-support-on-ubuntu-10.10-p2, which worked perfectly!

share|improve this answer
add comment

Your Answer

 
discard

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.