Nginx Serving PHP Files as Downloads: How to Fix Execution
Your Nginx installation is configured to serve PHP files as downloads instead of executing them. To resolve this issue, follow these steps:
1. Uncomment Listening Ports:
Edit /etc/nginx/sites-available/default and uncomment both the following lines:
listen 80; ## ipv4 listen [::]:80 default_server ipv6only=on; ## ipv6
2. Set Server Name:
Leave server_name as localhost:
server_name localhost;
3. Add index.php:
Add index.php to the index line:
index index.php index.html index.htm;
4. Enable PHP Location Block:
Uncomment the following PHP location block:
location ~ \.php$ { ... }
5. Set cgi.fix_pathinfo:
Edit /etc/php5/fpm/php.ini and set cgi.fix_pathinfo to 0:
cgi.fix_pathinfo = 0
6. Service Restart:
Restart Nginx and php5-fpm:
sudo service nginx restart && sudo service php5-fpm restart
These changes will ensure that PHP files are executed properly by Nginx.
The above is the detailed content of Why Are My PHP Files Downloading Instead of Executing in Nginx?. For more information, please follow other related articles on the PHP Chinese website!