有个discuz论坛一直用的是php5.3.3,php7出来以后看到大片大片的好评,性能大幅度的提升,心里就种草了。正好discuz官方最近也从3.2连续升级到了3.3、3.4版本,解决了很多外部网络依赖导致卡死等历史问题,顺便又把php7也支持了,那就升级一把。
首先,把web服务都停掉
# service php-fpm stop
Stopping php-fpm: [ OK ]
# service nginx stop
Stopping nginx: [ OK ]
查一下当前安装的php模块和插件有哪些
# yum list installed | grep php
php.x86_64 5.3.3-49.el6 @os
php-cli.x86_64 5.3.3-49.el6 @os
php-common.x86_64 5.3.3-49.el6 @os
php-devel.x86_64 5.3.3-49.el6 @os
php-fpm.x86_64 5.3.3-49.el6 @os
php-gd.x86_64 5.3.3-49.el6 @os
php-mbstring.x86_64 5.3.3-49.el6 @os
php-mysql.x86_64 5.3.3-49.el6 @os
php-pdo.x86_64 5.3.3-49.el6 @os
php-pear.noarch 1:1.9.4-5.el6 @os
php-pecl-apcu.x86_64 4.0.11-2.el6 @epel
php-pecl-igbinary.x86_64 1.2.1-1.el6 @epel
php-pecl-memcache.x86_64 3.0.5-4.el6 @os
php-pecl-redis.x86_64 2.2.8-1.el6 @epel
php-pecl-xhprof.x86_64 0.9.4-1.el6 @epel
php-xml.x86_64 5.3.3-49.el6 @os
更新一下php7的rpm源.因为是centOS 6的系统,所以选择了el6这个:
# rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
Retrieving http://mirror.webtatic.com/yum/el6/latest.rpm
warning: /var/tmp/rpm-tmp.vpifoH: Header V4 DSA/SHA1 Signature, key ID cf4c4ff9: NOKEY
Preparing... ########################################### [100%]
1:webtatic-release ########################################### [100%]
因为涉及的模块太多,一个一个处理容易出错,自动生成个脚本来处理一下
# echo "yum remove -y \\">removephp.sh
# # yum list installed | grep php |sed "s/^\(php\\S*\).*$/\\1 \\\\/" >> removephp.sh
这样把需要卸载的5.3.3的模块都放进去了。
把php5.3.3卸载完了还要把对应的php7的模块安装回去,所以先生成一个安装脚本
# echo "yum install \\">installphp7.sh
yum list installed | grep php |sed "s/^\(php\)\(\\S*\).*$/\\170w\\2 \\\\/" >>installphp7.sh
不过不是所有的包都能够顺利升级的,要检查一下这些5.3.3的模块是不是都有对应的php7的包
# yum list installed | grep php |sed "s/^\(php\)\(\\S*\)\..*$/yum search \\170w\\2 |grep 'No Matches found'/" |sh
Warning: No matches found for: php70w-pecl-xhprof
No Matches found
发现pecl-xhprof这个包没有对应的php7版本,那就只能vi一下,把这个包从installphp7.sh 里面删除掉了。
好了,现在一切准备就绪,开始移除php5.3.3
# sh removephp.sh
Loaded plugins: fastestmirror, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
...
...
Complete!
安装php7
# sh installphp7.sh
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* webtatic: uk.repo.webtatic.com
**No package php70w-pecl-memcache.x86_64 available.**
Resolving Dependencies
...
...
Install 15 Package(s)
Total download size: 12 M
Installed size: 50 M
Is this ok [y/N]: n
安装检查的时候报告了一个 No package php70w-pecl-memcache.x86_64 available 。可以先n以后修改installphp7.sh,再来也可以先y把其他的安装包都装好了再单独处理这个包。
检查一下这个包怎么了
yum search pecl-memcache
原来从PHP7开始,只支持pecl-memcached模块,不再支持古老的原生memcache模块了。可以修改一下installphp7.sh把memcache改成 memcached
# sed -i "s/pecl-memcache/pecl-memcached/" installphp7.sh
[root@VM_190_184_centos ~]# sh installphp7.sh
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
...
...
Install 17 Package(s)
Total download size: 13 M
Installed size: 51 M
Is this ok [y/N]: y
...
...
warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID cf4c4ff9: NOKEY
...
...
Complete!
中间有部分安装包报告NOKEY的warning,似乎缺少签名,键入y跳过。
看看是不是安装成功了
# php -v
PHP 7.0.21 (cli) (built: Jul 6 2017 11:37:10) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
试试启动一下服务
# service php-fpm start
Starting php-fpm: [ OK ]
#service nginx start
Starting nginx: [ OK ]
看起来蛮好。试试访问起来怎么样:
wget "http://localhost/index.php"
--2017-08-17 11:35:56-- http://localhost/index.php
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|... connected.
HTTP request sent, awaiting response... 502 Bad Gateway
2017-08-17 11:35:56 ERROR 502: Bad Gateway.
报告一个502错误,检查一下是什么问题:
# tail /var/log/nginx/error_log
2017/08/17 11:35:56 [crit] 14221#0: *70 connect() to unix:/tmp/php-fpm-www.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1 ......
nginx通过socket转发php-fpm被拒了,看看php-fpm的监听配置
# grep '^listen' /etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
原来php变成默认的监听9000端口的方式了,那还是改为socket方式吧。
# touch /tmp/php-fpm-www.sock
# sed -i "s/^listen = 127.0.0.1:9000/listen = \/tmp\/php-fpm-www.sock/" /etc/php-fpm.d/www.conf
# grep '^listen' /etc/php-fpm.d/www.conf
listen = /tmp/php-fpm-www.sock
listen.allowed_clients = 127.0.0.1
# service php-fpm restart
Stopping php-fpm: [ OK ]
Starting php-fpm: [ OK ]
# chmod 666 /tmp/php-fpm-www.sock
# wget "http://localhost/index.php"
--2017-08-17 11:49:44-- http://localhost/index.php
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: forum.php [following]
--2017-08-17 11:49:44-- http://localhost/forum.php
Connecting to localhost|127.0.0.1|... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
至此web服务已经恢复,可以打开浏览器验证了。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。