Nginx serves .php files as downloads, instead of executing them

There are several reasons why Nginx may serve PHP files as downloads instead of executing them. Here are a few things you can try to troubleshoot the issue:

  1. Make sure that you have the fastcgi_pass directive configured correctly in your Nginx configuration file. This directive specifies the address and port of the FastCGI server that will handle PHP requests.

  2. Check that the fastcgi_index directive is correctly set to the name of the PHP entry script. This directive specifies the default file that should be served when a directory is requested.

  3. Make sure that the root directive is correctly set to the root directory of your website. This directive specifies the root directory that should be used to search for the requested file.

  4. Check that the index directive is correctly set to the name of the PHP entry script. This directive specifies the default file that should be served when a directory is requested.

  5. Make sure that the include directive is correctly set to include the fastcgi_params file. This file contains a set of default FastCGI parameters that are used to process PHP requests.

  6. Check the permissions on your PHP files. Nginx may not be able to execute the PHP files if they are not readable or executable by the user that Nginx is running as.

  7. Check your Nginx error logs for any error messages that may provide more information about the issue.

I hope these suggestions help! If you are still having trouble, please provide more information about your Nginx configuration and any error messages you are seeing, and I will do my best to help.