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

What to do if nginx does not parse php

藏色散人
藏色散人Original
2020-11-01 14:11:023484browse

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;
        }

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

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

sudo apt-get install php5-fpm
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!

Statement:
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