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.

After failing to get FastCGI to work with PHP I have installed the PHP-FPM service which is reported to work out of the box, however PHP files are downloading instead of executing.

This is what I have in the nginx.conf file:

server {
    listen 80;
    server_name  pubserver;
    root         /usr/share/nginx/html;
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
        fastcgi_param  PATH_INFO $fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }
}

The command netstat -tulpn | grep :9000 displays this which suggests PHP-FPM is running:

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      1058/php-fpm.conf)
share|improve this question
    
I have tried on the same server with Apache instead of nginx and it works with Apache but I want to use nginx. Any ideas what I'm doing wrong? –  Daniel Jun 1 '12 at 20:12
    
index index.php; –  Dmitry Verkhoturov Jun 1 '12 at 20:42
    
Yes, I have that but outside server { }. Thank you. –  Daniel Jun 1 '12 at 20:57
    
add comment

1 Answer

up vote 1 down vote accepted

Finally managed to get it working. After checking the logs I noticed there were errors like this which indicated redirect cycles:

2012/06/02 09:48:30 [error] 1699#0: *14 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/favicon.ico"

So I thoroughly checked the nginx.conf file and found that this line:

include /etc/nginx/conf.d/*.conf;

was loading 3 other files, namely:

  • default.conf
  • ssl.conf
  • virtual.conf

After opening default.conf I noticed the following rules were already there:

server {
    listen 80;
    server_name  _;
    root         /usr/share/nginx/html/demo;
    index        index.php;

    location ~ \.php$ {
        include        /etc/nginx/fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;

    }
}

Probably because I installed nginx and PHP-FPM from the CentOS repository it came already configured. Apparently I rushed to configure the PHP service before testing if it was working.

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.