3.1 删除php安装nginx和php-fpm5.6

1. 查看所有php相关的rpm包,并卸载php

1.1 yum命令查看

CentOS上PHP完全卸载,想把PHP卸载干净,直接用yum的remove命令是不行的,需要查看有多少rpm包,然后按照依赖顺序逐一卸载。

[root@localhost]# rpm -qa | grep php
php-cli-5.3.3-22.el6.x86_64
php-pdo-5.3.3-22.el6.x86_64
php-gd-5.3.3-22.el6.x86_64
php-fpm-5.3.3-22.el6.x86_64
php-common-5.3.3-22.el6.x86_64
php-5.3.3-22.el6.x86_64
php-xml-5.3.3-22.el6.x86_64
php-pear-1.9.4-4.el6.noarch;

1.2.按依赖顺序进行删除

[root@localhost]# rpm -e php-fpm-5.3.3-22.el6.x86_64
[root@localhost]# rpm-e php-pdo-5.3.3-22.el6.x86_64
[root@localhost]# rpm -e php-pear-1.9.4-4.el6.noarch
[root@localhost]# rpm-e php-cli-5.3.3-22.el6.x86_64
[root@localhost]# rpm -e php-5.3.3-22.el6.x86_64
[root@localhost]# rpm-e php-xml-5.3.3-22.el6.x86_64
[root@localhost]# rpm -e php-gd-5.3.3-22.el6.x86_64
[root@localhost]# rpm-e php-common-5.3.3-22.el6.x86_64

==========================

2. centos7安装nginx和php

2.1 nginx安装

参考网址:https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7

[root@localhost]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@localhost]# yum install nginx

2.2 安装PHP和php-fpm

[root@localhost]# yum install --enablerepo=remi --enablerepo=remi-php56 php php-fpm

安装的是5.6的php,所以的指定这个源里面安装php-fpm,不然一直报错

2.3 修改php配置文件

[root@localhost]# vi /etc/php.ini
cgi.fix_pathinfo=0    # 修改成0

(这个配置值说是不安全的设置,参考网址:http://www.laruence.com/2010/05/20/1495.html)

2.4 修改配置文件

vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name www.scchary.com;
root /home/samba1/public_html;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
#root /usr/share/nginx/html;
#root /home/samba1/public_html;
index index.php index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root /home/samba1/public_html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

ESC键返回编辑
输入

:wq # 保存并退出

#修改上面配置文件的时候,运行php文件的时候,老是显示没有找到,后来在这里找到了答案,参考网址http://www.nginx.cn/562.html

server {
listen [::]:80;
server_name example.com www.example.com;
access_log /var/www/logs/example.com.access.log;

location / {
root /var/www/example.com;
index index.html index.htm index.pl;
}

location /images {
autoindex on;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/example.com$fastcgi_script_name;
include fastcgi_params;
}
}

一个明显的问题就是root指令被放到了location / 块。如果root指令被定义在location块中那么该root指令只能对其所在的location生效。
其它locaiont中没有root指令,像location /images块不会匹配任何请求,需要在每个请求中重复配置root指令来解决这个问题。
因此我们需要把root指令放在server块,这样各个location就会继承父server块定义的 d o c u m e n t r o o t l o c a t i o n document_root,如果某个location需要定义一个不同的 document_root,则可以在location单独定义一个root指令。
这里不知道怎么把root指令放在server中。

另一个问题就是fastCGI参数SCRIPT_FILENAME 是写死的。
如果修改了root指令的值或者移动文件到别的目录,php-fpm会返回“No input file specified”错误,因为SCRIPT_FILENAME在配置中是写死的并没有随着$doucument_root变化而变化,可以修改SCRIPT_FILENAME配置如下:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

所以不能忘记在server块中配置root指令,不然 d o c u m e n t r o o t document_root的值为空,只会传 fastcgi_script_name到php-fpm,这样就会导致“No input file specified”错误。

最后在测试php文件里面输出phpinfo的时候,出现了一个未定义时区的错误,修改了配置文件还是报错,最后重启了下php-fpm就好了

[root@localhost]# service php-fpm start

2.5 关于php-cgi.sock已监听的错误提示

若结果仍然提示

[root@host ~]# service php-fpm start
Starting php-fpm [11-Apr-2019 15:27:19] ERROR: An another FPM instance seems to already listen on /tmp/php-cgi.sock
[11-Apr-2019 15:27:19] ERROR: FPM initialization failed
 failed

可通过查找php-cgi.sock,并删除,重启php-fpm即可

[root@host ~]# find / -name php-cgi.sock
[root@host tmp]# rm php-cgi.sock
rm: remove socket 'php-cgi.sock'? y

猜你喜欢

转载自blog.csdn.net/ptmicky/article/details/89214865
3.1
今日推荐