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;
}
}
                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.
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.
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.
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.
Try to remove this block:
location = /index.php {
    root   /var/www/html;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With