(SOS)centos7, nginx cannot parse php file

Keywords: Operation & Maintenance PHP Nginx

I. problem description

When accessing the *. PHP file, the content of the file is not displayed, but the file to be accessed is downloaded directly, such as index.php. But it's normal to visit index.html. After reading all the posts on the Internet that have encountered this problem, we still haven't found a solution, so we post for help.

II. Problem ideas

  • 1.nginx and PHP FPM processes are up, and the listening ports are all right
[root@~]# ps -ef |grep nginx
root      1045     1  0 09:40 ?        00:00:00 nginx: master process /usr/sbin/nginx
www-data  1049  1045  0 09:40 ?        00:00:00 nginx: worker process
root      2695  2675  0 10:21 pts/1    00:00:00 grep --color=auto nginx
[root@~]# ps -ef |grep php-fpm
root       697     1  0 09:40 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www-data  1010   697  0 09:40 ?        00:00:00 php-fpm: pool www
www-data  1011   697  0 09:40 ?        00:00:00 php-fpm: pool www
www-data  1022   697  0 09:40 ?        00:00:00 php-fpm: pool www
www-data  1023   697  0 09:40 ?        00:00:00 php-fpm: pool www
www-data  1024   697  0 09:40 ?        00:00:00 php-fpm: pool www
root      2698  2675  0 10:22 pts/1    00:00:00 grep --color=auto php-fpm
[root@~]# netstat -tunlp|grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      697/php-fpm: master 
  • 2. Check the configuration of nginx.cnf as follows. The Internet is mainly about the fastcgi ﹣ param parameter. Three writing methods have been tried and none of them have taken effect.
        location / {
	    root html;
            index index.html index.htm index.php;
        }

	location ~ \.php$ {
             #root /usr/share/nginx/html; 
             root html;
             fastcgi_pass 127.0.0.1:9000;
             fastcgi_index index.php;
             #fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
             include fastcgi_params;
          }

[root@~]# ls  /usr/share/nginx/html/
404.html  50x.html  index.html  index.php  
nginx-logo.png  poweredby.png  wordpress  wordpress-4.9.4-zh_CN.tar.gz

  • 3. It seems that there is nothing abnormal in the log log of PHP FPM
[root@~]# tail -f /var/log/php-fpm/error.log 
[03-Nov-2018 00:00:43] NOTICE: Terminating ...
[03-Nov-2018 00:00:43] NOTICE: exiting, bye-bye!
[03-Nov-2018 00:00:47] NOTICE: fpm is running, pid 3778
[03-Nov-2018 00:00:47] NOTICE: ready to handle connections
[03-Nov-2018 00:00:47] NOTICE: systemd monitor interval set to 10000ms
[03-Nov-2018 09:40:36] NOTICE: Terminating ...
[03-Nov-2018 09:40:36] NOTICE: exiting, bye-bye!
[03-Nov-2018 09:40:52] NOTICE: fpm is running, pid 697
[03-Nov-2018 09:40:52] NOTICE: ready to handle connections
[03-Nov-2018 09:40:52] NOTICE: systemd monitor interval set to 10000ms
  • 4. I have set the user names of nginx and PHP FDM to WWW data
[root@~]# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

#user nginx;
user www-data;

[root@~]# cat /etc/php-fpm.d/www.conf |grep www-data
user = www-data
group = www-data

SOS

Read a lot of posts on the Internet, basically just modify nginx.cnf. But all the methods I tried didn't work. In centos7, the default html path is / usr/share/nginx/html /. It feels like nginx didn't call PHP FPM module, but there is no way to solve this problem???

Posted by bbaassiri on Tue, 10 Dec 2019 11:46:50 -0800