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?

Mary-Kate Olsen
Release: 2024-12-03 12:22:11
Original
673 people have browsed it

Why Are My .php Files Downloading Instead of Executing in Nginx?

Nginx Configuration Issue: .php Files Served as Downloads Instead of Executed

When attempting to install an NGINX and PHP stack, a user encountered an issue where .php files were being served as downloads instead of being executed. Below is the solution to resolve this issue:

In /etc/nginx/sites-available/default:

  • Uncomment both "listen" lines to enable Nginx to listen on both IPv4 and IPv6.
  • Edit the "index" line to include "index.php" as the first index file.

Specific Edit Commands:

sudo nano /etc/nginx/sites-available/default
Copy after login
# listen for ipv4; this line is default and implied
listen 80; 

# listen for ipv6
listen [::]:80 default_server ipv6only=on; 

root /usr/share/nginx/www;

# Index files in order
index index.php index.html index.htm;
Copy after login
  • Uncomment the "location ~ .php$" block to pass PHP scripts to the FastCGI server.

Additional Configuration Tips:

  • Ensure "cgi.fix_pathinfo" is set to 0 in /etc/php5/fpm/php.ini.
  • Restart Nginx and php5-fpm using the following commands:
sudo service nginx restart && sudo service php5-fpm restart
Copy after login

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