Search code examples
phpnginxfastcgi

Nginx and FastCGI downloads PHP files instead of processing them


I'm running on Windows 7 (64-bit), with PHP 5.4.12, and Nginx 1.5.8.

I have read many tutorials on setting this up, and troubleshooting this issue, which is that when requesting a PHP file from my localhost, it downloads it as a file instead of displaying the PHP page. Below is my nginx.conf file:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen 8081;
        server_name localhost;
        access_log C:/nginx/logs/access.log;
        error_log C:/nginx/logs/error.log;
        root C:/nginx/html;

        fastcgi_param  REDIRECT_STATUS    200;

        location ~ \.php$ {
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
        }
    }

}

I'm running nginx.exe manually through the command prompt. I've also tried starting php-cgi.exe manually first at a separate command prompt, like so:

C:\php5.4.12\php-cgi.exe -b 127.0.0.1:9000

The php file I'm requesting is within C:/nginx/html, and I'm requesting it as:

http://localhost:8081/info.php

And it downloads it. The contents of this PHP file are:

<?php
phpinfo();
?>

How can I possibly get my PHP scripts to run in this environment. Anyone have experience with this?


Solution

  • Try to change default_type application/octet-stream; to default_type text/html; Maybe your php-script does not set a content MIME type and it goes from nginx.