Home  >  Article  >  Backend Development  >  How to solve centos nginx php error problem

How to solve centos nginx php error problem

藏色散人
藏色散人Original
2021-09-15 09:23:442515browse

centos nginx php error solution: 1. Analyze whether php-fpm is installed, if not, install php-fpm; 2. Modify the nginx.conf file or default.conf; 3. Save the file and restart Just nginx.

How to solve centos nginx php error problem

The operating environment of this article: centOS6.8 system, PHP7.1 version, DELL G3 computer

How to solve centos nginx php error question?

CentOS6.10 Nginx cannot parse php files

1. Problem description:

1). Prerequisite:

nginx has been installed and can access

2). Problem:

When accessing the .php file, it will be downloaded by default, or it will prompt "File not found.”

3). Local environment

PHP 版本:
 # php -v
PHP 5.3.3 (cli) (built: Mar 22 2017 12:27:09) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
Nginx 版本:[root@bogon sbin]# ./nginx -v
nginx version: nginx/1.11.6

2. Solution

1). Analyze whether php-fpm is installed

You can run the command service php-fpm start. If it shows that it cannot be recognized, it means it is not installed.

2). If php-fpm is not installed

You can execute the installation command: yum install php-fpm and then run the command service php-fpm start

3). If it is already installed I have installed php-fpm and still cannot parse the .php file

(1). Modify the nginx.conf file or default.conf, as shown in the figure below, and modify several pieces of information. For example, "root" refers to my nginx root directory, which can be configured according to your own situation

How to solve centos nginx php error problem

(2). Save the file and restart nginx, command: service nginx restart (3). At this time, the browser can access the .php file (if it is not accessed locally, be sure to turn off the firewall)


server{
        listen 80;
        server_name app-hpoption-admin-test.azfaster.com;
        root   /data/wwwroot/blog/public;
        charset utf-8;

        location / {
                index index.php index.html ;
                try_files $uri $uri/ /index.php?$query_string;

        }

        #location ~ .php$ {
        #       fastcgi_pass 127.0.0.1:9000;
        #       fastcgi_index index.php;
        #       fastcgi_param SCRIPT_FILENAME /var/www/test/public$fastcgi_script_name;
        #       include  fastcgi_params;
        #}

         location ~ .*\.(php|php5)?$ {
                # fastcgi_pass  unix:/dev/shm/php-cgi.sock;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /data/wwwroot/blog/public$fastcgi_script_name;
                include fastcgi_params;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root html;
        }
}

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to solve centos nginx php error problem. 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