Home > Backend Development > PHP Tutorial > Why Are My PHP Files Downloading Instead of Executing in Nginx?

Why Are My PHP Files Downloading Instead of Executing in Nginx?

Linda Hamilton
Release: 2024-12-01 17:17:15
Original
426 people have browsed it

Why Are My PHP Files Downloading Instead of Executing in Nginx?

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
Copy after login

2. Set Server Name:

Leave server_name as localhost:

server_name localhost;
Copy after login

3. Add index.php:

Add index.php to the index line:

index index.php index.html index.htm;
Copy after login

4. Enable PHP Location Block:

Uncomment the following PHP location block:

location ~ \.php$ { ... }
Copy after login

5. Set cgi.fix_pathinfo:

Edit /etc/php5/fpm/php.ini and set cgi.fix_pathinfo to 0:

cgi.fix_pathinfo = 0
Copy after login

6. Service Restart:

Restart Nginx and php5-fpm:

sudo service nginx restart && sudo service php5-fpm restart
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template