Ryan Weiss
Ryan Weiss

Reputation: 1318

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?

Upvotes: 4

Views: 15191

Answers (4)

chnateag
chnateag

Reputation: 1

It was http2 enabled on port 80 for me too. Disabling it solved the issue.

Upvotes: 0

stasionok
stasionok

Reputation: 11

I found that if you have the http2 directive for port 80 on the server. http2 works only under https. Therefore, if you remove http2, it should solve your issue.

Upvotes: 0

RobbyKrlos
RobbyKrlos

Reputation: 121

Try placing " * " here

location ~* \.php$ {

There is something wrong with your paths, and nginx does not know the path accessed via URL is the path it should pass through "fastcgi_pass". Therefore, it gives the file for download.

Check your error log from :

C:/nginx/logs/error.log;

Do you have a "C:/nginx/html/info.php;"?

Upvotes: 0

TreeNode
TreeNode

Reputation: 482

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.

Upvotes: 5

Related Questions