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 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 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;  # 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* 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
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,, which worked perfectly!

share|improve this answer

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.