Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX and PHP-FPM is downloading index.php instead of processing it

Tags:

php

nginx

I recently installed NGINX and PHP-FPM on a Centos6 server. I'm able to view other php pages on my site, but for some reason my index.php file gets downloaded rather than processed like a normal php page.

Here is the nginx config:

# The default server
#
server {
listen       80 default_server;
server_name  example.com;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
    root   /var/www/html/;
    index  index.php index.html index.htm;
}

error_page  404              /404.html;
location = /index.php {
    root   /var/www/html;
}

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    root           /var/www/html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny  all;
}

}
like image 821
Salty Avatar asked May 25 '13 08:05

Salty


People also ask

Why do PHP files download instead of executed?

This is normally due to an improper handler code. In the . htaccess file, you will want to ensure the handler code matches your version of php. If it does not, the php files may try to download instead of process.

How does PHP-FPM work with NGINX?

With the configuration of Nginx, PHP and the PHP-FPM module complete, and a new file named info. php added to the web server, simply open a browser to http://localhost/info.php to test the setup. The PHP info page, attesting to the fact that the install on Nginx of PHP 8.1, will appear.

Does NGINX need PHP-FPM?

1. Install PHP-FPM. Nginx doesn't know how to run a PHP script of its own. It needs a PHP module like PHP-FPM to efficiently manage PHP scripts.

Does NGINX support PHP by default?

NGINX does not execute PHP scripts by default and must be configured to do so. This tutorial helps with your NGINX and PHP configuration to enable and test PHP capabilities with your server.


1 Answers

Try to remove this block:

location = /index.php {
    root   /var/www/html;
}
like image 95
Valery Viktorovsky Avatar answered Oct 08 '22 17:10

Valery Viktorovsky