Home > Backend Development > PHP Problem > What to do if nginx does not parse php

What to do if nginx does not parse php

藏色散人
Release: 2023-03-06 21:42:01
Original
3521 people have browsed it

The solution to nginx not parsing php: first find the nginx configuration file; then remove the corresponding comments; then restart nginx and visit the page; finally reinstall php5-fpm and visit again.

What to do if nginx does not parse php

Recommended: "PHP Video Tutorial"

Nginx cannot parse php files

0x00: Problem description

When accessing the *.php file, the content of the file is not displayed but the file to be accessed is directly downloaded, such as index.php.

0x01: Solution

:: Find the nginx configuration file and modify the file to support php

The configuration file location is: /etc/nginx/sites_available/ below, If you have not created any other configuration files, there should be a default configuration file named "default".

1. Open the configuration file and find the following content in the file:

location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
 
                # With php5-cgi alone:
                # fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
Copy after login

2. If you find that the above content is commented out, remove the corresponding comment.

3. Restart nginx and visit the page.

sudo service nginx restart
Copy after login

4. If a 503 error occurs when accessing again, please install php5-fpm and access

sudo apt-get install php5-fpm
Copy after login
again.

The above is the detailed content of What to do if nginx does not parse php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template