4

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?

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting, but it worked for me too! Would be great to hear the tech explanation for this...
0

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;"?

Comments

0

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.

Comments

0

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

1 Comment

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.