您好,欢迎访问一九零五行业门户网

在CentOS上把PHP从5.4升级到5.5

在centos上把php从5.4升级到5.5 摘要:本文记录了在centos 6.3上,把php从5.4.8升级到5.5.13的过程。 1. 概述 在我做的一个项目中,最近我对生产服务器上的一系列系统软件进行了升级,包括git、nginx、mysql和php。这篇文章讲的是升级php的过程,其他软件的
在centos上把php从5.4升级到5.5摘要:本文记录了在centos 6.3上,把php从5.4.8升级到5.5.13的过程。
1. 概述在我做的一个项目中,最近我对生产服务器上的一系列系统软件进行了升级,包括git、nginx、mysql和php。这篇文章讲的是升级php的过程,其他软件的升级,可见下面列出的文章。
在centos上把git从1.7.1升级到1.7.12.4在centos上把nginx从1.2.4升级到1.6.0在centos上把mysql从5.5升级到5.6在centos上把php从5.4升级到5.5 (本文)在我加入这个项目之前,服务器上的php已经安装设置好了,我只是正常使用而已。现在过去1年了,所有的开发工作都告一段落,有时间升级服务器上的软件了。升级这种事情是应当经常做的,倒不是为了追最新版本,而是当正式版本发放出来的时候,应该及时更新, 以便获得最新的更正、补丁,避免服务器上的漏洞,减少安全隐患。
升级是在今年6月13-14日进行的,到今天才有空做个记录,便于日后参考。
2. 计划计划就是预案,就是事先的准备(包括心理上的)、更明细的步骤、对各种情况及对意外的对策,当然,我们不可能面面俱到,预测一切,不然就成神了,所以要随时准备脱稿演出,think out of the box。
2.1 了解情况计划要有针对性,所以要先”踩点儿“。
通过在系统上,用find之类的命令,或者通过网页用phpinfo()函数来显示关于php的信息,可以找到php安装在/usr/local/php目录下。这说明php是从源代码编译安装的,因为yum和rpm是不会安装到/usr/local/php这个路径的。在qq群友的提示下,找到php 5.4.8的源代码位于/usr/local/src/php-5.4.8目录中,进一步确认php是从源代码编译安装的。
查看php版本:
# /usr/local/php/bin/php -vphp 5.4.8 (cli) (built: nov 13 2012 00:08:08)copyright (c) 1997-2012 the php groupzend engine v2.4.0, copyright (c) 1998-2012 zend tehnologies
再查看php-fpm的运行情况。那两天看文档,我才知道有php-fpm(fastcgi process manager)这么个东西,在5.4之后已经包括在php之中了,详见参考资料[]13][14]。
查看php-fpm使用的端口:
# netstat -ntpul | grep php-fpmtcp 0 0 127.0.0.1:9000 0.0.0.0:* listen 2881/php-fpm
查看php-fpm的进程:
# ps aux | grep php-fpmuser pid %cpu %mem vsz rss tty stat start time commandroot 2881 0.0 0.2 204172 2064 ? ss 2013 38:09 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)www 18982 0.0 1.4 212796 14816 ? s 19:12 0:03 php-fpm: pool wwwwww 18983 0.0 1.4 211996 14572 ? s 19:13 0:03 php-fpm: pool wwwwww 18984 0.0 1.4 212276 14876 ? s 19:13 0:03 php-fpm: pool wwwroot 19144 0.0 0.0 103236 864 pts/0 s+ 23:29 0:00 grep php-fpm
查看php-fpm的版本:
# /usr/local/php/sbin/php-fpm -vphp 5.4.8 (fpm-fcgi) (built: nov 13 2012 00:15:58)copyright (c) 1997-2012 the php groupzend engine v2.4.0, copyright (c) 1998-2012 zend technologies
查看上次系统启动的时间,这是怕安装的东西没重启而没有生效:
# who -b system boot 2013-01-04 01:07# last rebootreboot system boot 2.6.32-279.14.1. fri jan 4 01:07 - 20:36 (526+19:29)reboot system boot 2.6.32-220.13.1. mon nov 12 17:53 - 20:36 (579+02:42)reboot system boot 2.6.32-220.13.1. thu may 10 17:12 - 17:13 (00:01)reboot system boot 2.6.32-220.13.1. wed may 9 15:31 - 15:36 (00:04)reboot system boot 2.6.32-220.13.1. wed may 9 15:03 - 15:29 (00:26)reboot system boot 2.6.32-220.13.1. wed may 9 10:09 - 12:26 (02:16)reboot system boot 2.6.32-220.13.1. thu may 3 17:23 - 17:25 (00:02)reboot system boot 2.6.32-220.13.1. fri may 4 01:17 - 17:22 (-7:-54)reboot system boot 2.6.32-220.13.1. fri apr 20 21:33 - 17:22 (12+19:48)reboot system boot 2.6.32-220.13.1. sat apr 21 03:39 - 17:22 (12+13:42)reboot system boot 2.6.32-220.13.1. fri apr 20 18:02 - 17:22 (12+23:19)reboot system boot 2.6.32-220.13.1. thu apr 19 19:51 - 17:59 (22:07)
其实这种担心是多余的,因为linux和windows不一样,基本上新安装的东西,都有命令行可以重启,只要你知道相应的命令行,不需要重启整个系统。
小结,现有的php 5.4.8安装在/usr/local/php目录下,是编译安装的,源代码位于/usr/local/src/php-5.4.8目录中。编译安装的好处是,可以自己定制,增减php扩展等等。建议,如无必要,不要使用编译安装,因为这样的安装,操作麻烦,对操作者的要求比较高,又无法利用yum和rpm这样的工具,不便于升级、卸载。
这也是为什么我用yum update php命令无法直接升级php的原因,因为yum或者rpm根本不知道用源代码编译安装的php。下面是我尝试的结果:
# yum update phploaded plugins: fastestmirrorloading mirror speeds from cached hostfile * base: mirrors.163.com * epel: mirrors.hust.edu.cn * extras: mirrors.163.com * remi: mirrors.hustunique.com * remi-php55: mirrors.hustunique.com * updates: mirrors.163.comsetting up update processpackage(s) php available, but not installed.no packages marked for update
可见,yum没有找到已经安装的php包,所以没什么可以升级的。孤独的编译安装,没人待见,看来要在角落里终老一生了。
2.2 确定计划经过在几个cakephp、php相关的qq群里,向其他朋友的请教和讨论,(此处略去15000字),其实这是和上面的”踩点儿“互相掺杂在一起进行的。在这里要特别感谢cakephp群中的christian和严谨的php hhvm mysql群中的linux 管理员(freax)两位朋友。最终在朋友们的帮助下形成了下面的计划要点:
保留原有编译安装的php 5.4.8,没必要去动它,不用就是了用yum安装php 5.5.13,配置php-fpm 5.5.13使用另一个端口(比如9001)修改nginx的配置,使用在新端口上的php-fpm 5.5.13如何重启php-fpm?
答:php-fpm在5.4以后默认是二进制文件了,不再用service php-fpm start这种启动了。可以在/etc/rc.local (link to /etc/rc.d/rc.local) 加上这条命令前期的调研、计划,花了差不多2天时间,而之后的安装、配置,也就用了3-4个小时。
3. 安装、配置php 5.5.13根据这两天读的文档,确定使用remi安装库,使用yum来安装php 5.5.13。
3.1 添加remi安装库下面的操作依据参考资料[4]:
# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm# rpm -uvh remi-release-6*.rpm epel-release-6*.rpm
3.2 用yum安装php 5.5.13从之前php 5.4.8下phpinfo()的输出,知道了旧的php 5.4.8上安装的php扩展,这样确定了下面需要安装的包(命令yum install之后的参数):
# yum install php php-fpm php-gd php-mysqlnd php-mcrypt php-mbstring php-pdodependencies resolved================================================================================ package arch version repository size================================================================================installing: libjpeg-turbo x86_64 1.2.1-3.el6_5 updates 174 k replacing libjpeg.x86_64 6b-46.el6 libjpeg-turbo-devel x86_64 1.2.1-3.el6_5 updates 96 k replacing libjpeg-devel.x86_64 6b-46.el6 php x86_64 5.5.13-3.el6.remi remi-php55 2.6 m php-fpm x86_64 5.5.13-3.el6.remi remi-php55 1.3 m php-gd x86_64 5.5.13-3.el6.remi remi-php55 69 k php-mbstring x86_64 5.5.13-3.el6.remi remi-php55 958 k php-mcrypt x86_64 5.5.13-3.el6.remi remi-php55 40 k php-mysqlnd x86_64 5.5.13-3.el6.remi remi-php55 261 k php-pdo x86_64 5.5.13-3.el6.remi remi-php55 109 kinstalling for dependencies: apr-util-ldap x86_64 1.3.9-3.el6_0.1 base 15 k fontconfig x86_64 2.8.0-3.el6 base 186 k gd-last x86_64 2.1.0-2.el6.remi remi 129 k httpd x86_64 2.2.15-30.el6.centos updates 821 k httpd-tools x86_64 2.2.15-30.el6.centos updates 73 k libx11 x86_64 1.5.0-4.el6 base 584 k libx11-common noarch 1.5.0-4.el6 base 192 k libxau x86_64 1.0.6-4.el6 base 24 k libxpm x86_64 3.5.10-2.el6 base 51 k libmcrypt x86_64 2.5.8-9.el6 epel 96 k libtiff x86_64 3.9.4-10.el6_5 updates 343 k libxcb x86_64 1.8.1-1.el6 base 110 k libxslt x86_64 1.1.26-2.el6_3.1 base 452 k mailcap noarch 2.1.31-2.el6 base 27 k php-cli x86_64 5.5.13-3.el6.remi remi-php55 2.5 m php-common x86_64 5.5.13-3.el6.remi remi-php55 1.0 m php-pear noarch 1:1.9.4-28.el6.remi remi 373 k php-pecl-jsonc x86_64 1.3.5-1.el6.remi.5.5 remi-php55 46 k php-pecl-zip x86_64 1.12.4-1.el6.remi.5.5 remi-php55 269 k php-process x86_64 5.5.13-3.el6.remi remi-php55 54 k php-xml x86_64 5.5.13-3.el6.remi remi-php55 206 k t1lib x86_64 5.1.2-6.el6_2.1 base 160 ktransaction summary================================================================================install 31 package(s)
yum自动计算出需要的依赖安装包,总共有31个安装包需要下载、安装。
下面询问是否继续下载,回答y,并按回车即可继续:
total download size: 13 mis this ok [y/n]: ydownloading packages:(1/31): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm | 15 kb 00:00(2/31): fontconfig-2.8.0-3.el6.x86_64.rpm | 186 kb 00:00(3/31): gd-last-2.1.0-2.el6.remi.x86_64.rpm | 129 kb 00:00(4/31): httpd-2.2.15-30.el6.centos.x86_64.rpm | 821 kb 00:00(5/31): httpd-tools-2.2.15-30.el6.centos.x86_64.rpm | 73 kb 00:00(6/31): libx11-1.5.0-4.el6.x86_64.rpm | 584 kb 00:00(7/31): libx11-common-1.5.0-4.el6.noarch.rpm | 192 kb 00:00(8/31): libxau-1.0.6-4.el6.x86_64.rpm | 24 kb 00:00(9/31): libxpm-3.5.10-2.el6.x86_64.rpm | 51 kb 00:00(10/31): libjpeg-turbo-1.2.1-3.el6_5.x86_64.rpm | 174 kb 00:00(11/31): libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64.rpm | 96 kb 00:00(12/31): libmcrypt-2.5.8-9.el6.x86_64.rpm | 96 kb 00:00(13/31): libtiff-3.9.4-10.el6_5.x86_64.rpm | 343 kb 00:00(14/31): libxcb-1.8.1-1.el6.x86_64.rpm | 110 kb 00:00(15/31): libxslt-1.1.26-2.el6_3.1.x86_64.rpm | 452 kb 00:00(16/31): mailcap-2.1.31-2.el6.noarch.rpm | 27 kb 00:00(17/31): php-5.5.13-3.el6.remi.x86_64.rpm | 2.6 mb 00:00(18/31): php-cli-5.5.13-3.el6.remi.x86_64.rpm | 2.5 mb 00:00(19/31): php-common-5.5.13-3.el6.remi.x86_64.rpm | 1.0 mb 00:00(20/31): php-fpm-5.5.13-3.el6.remi.x86_64.rpm | 1.3 mb 00:00(21/31): php-gd-5.5.13-3.el6.remi.x86_64.rpm | 69 kb 00:00(22/31): php-mbstring-5.5.13-3.el6.remi.x86_64.rpm | 958 kb 00:00(23/31): php-mcrypt-5.5.13-3.el6.remi.x86_64.rpm | 40 kb 00:00(24/31): php-mysqlnd-5.5.13-3.el6.remi.x86_64.rpm | 261 kb 00:00(25/31): php-pdo-5.5.13-3.el6.remi.x86_64.rpm | 109 kb 00:00(26/31): php-pear-1.9.4-28.el6.remi.noarch.rpm | 373 kb 00:00(27/31): php-pecl-jsonc-1.3.5-1.el6.remi.5.5.x86_64.rpm | 46 kb 00:00(28/31): php-pecl-zip-1.12.4-1.el6.remi.5.5.x86_64.rpm | 269 kb 00:00(29/31): php-process-5.5.13-3.el6.remi.x86_64.rpm | 54 kb 00:00(30/31): php-xml-5.5.13-3.el6.remi.x86_64.rpm | 206 kb 00:00(31/31): t1lib-5.1.2-6.el6_2.1.x86_64.rpm | 160 kb 00:00--------------------------------------------------------------------------------total 3.6 mb/s | 13 mb 00:03
之后还有一些is this ok [y/n]:的问题,一律回答y。经过一轮问答和安装,最后完成时的小结为:
installed: libjpeg-turbo.x86_64 0:1.2.1-3.el6_5 libjpeg-turbo-devel.x86_64 0:1.2.1-3.el6_5 php.x86_64 0:5.5.13-3.el6.remi php-fpm.x86_64 0:5.5.13-3.el6.remi php-gd.x86_64 0:5.5.13-3.el6.remi php-mbstring.x86_64 0:5.5.13-3.el6.remi php-mcrypt.x86_64 0:5.5.13-3.el6.remi php-mysqlnd.x86_64 0:5.5.13-3.el6.remi php-pdo.x86_64 0:5.5.13-3.el6.remidependency installed: apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 fontconfig.x86_64 0:2.8.0-3.el6 gd-last.x86_64 0:2.1.0-2.el6.remi httpd.x86_64 0:2.2.15-30.el6.centos httpd-tools.x86_64 0:2.2.15-30.el6.centos libx11.x86_64 0:1.5.0-4.el6 libx11-common.noarch 0:1.5.0-4.el6 libxau.x86_64 0:1.0.6-4.el6 libxpm.x86_64 0:3.5.10-2.el6 libmcrypt.x86_64 0:2.5.8-9.el6 libtiff.x86_64 0:3.9.4-10.el6_5 libxcb.x86_64 0:1.8.1-1.el6 libxslt.x86_64 0:1.1.26-2.el6_3.1 mailcap.noarch 0:2.1.31-2.el6 php-cli.x86_64 0:5.5.13-3.el6.remi php-common.x86_64 0:5.5.13-3.el6.remi php-pear.noarch 1:1.9.4-28.el6.remi php-pecl-jsonc.x86_64 0:1.3.5-1.el6.remi.5.5 php-pecl-zip.x86_64 0:1.12.4-1.el6.remi.5.5 php-process.x86_64 0:5.5.13-3.el6.remi php-xml.x86_64 0:5.5.13-3.el6.remi t1lib.x86_64 0:5.1.2-6.el6_2.1replaced: libjpeg.x86_64 0:6b-46.el6 libjpeg-devel.x86_64 0:6b-46.el6complete!
3.3 配置php-fpm的启动因为使用yum安装,安装过程已经拷贝好了php-fpm的服务daemon,只需确保php-fpm服务能在系统重启时自动启动就行了:
# chkconfig php-fpm on
查看php-fpm服务的自启动状态:
# chkconfig --list php-fpmphp-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
正确。
3.4 停止php-fpm 5.4.8查看php-fpm 5.4.8的进程:
# ps aux | grep php-fpmroot 2881 0.0 0.1 204172 1972 ? ss 2013 38:13 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)www 19378 0.0 1.4 212764 14736 ? s 10:30 0:14 php-fpm: pool wwwwww 19379 0.0 1.5 213352 15888 ? s 10:32 0:13 php-fpm: pool wwwwww 19657 0.0 1.3 212076 13964 ? s 18:45 0:02 php-fpm: pool wwwroot 20083 0.0 0.0 103236 864 pts/0 s+ 22:40 0:00 grep php-fpm
可见,当前php-fpm 5.54.8进程的进程号(pid)是2881,注意其使用的配置文件/usr/local/php/etc/php-fpm.conf位于编译安装php的目录,证实了这是php-fpm 5.54.8进程。其余进程为其子进程,而grep php-fpm是查看进程这个命令的进程。
中断php-fpm 5.54.8进程:
# kill -term 2881
再次查看php-fpm的进程:
# ps aux | grep php-fpmroot 20087 0.0 0.0 103236 864 pts/0 s+ 22:43 0:00 grep php-fpm
已经没有php-fpm的进程了,唯一剩下的grep php-fpm是查看进程这个命令的进程。
3.5 启动php-fpm 5.5.13php-fpm的配置,我遵照的是参考资料[10],这是一个分级结构的配置文件,多个配置文件各司其职,便于更换配置,启用、停止配置的各模块也更容易。
启动php-fpm服务:
# service php-fpm startstarting php-fpm: [ ok ]
顺利启动。
再查看其进程:
# ps aux | grep php-fpmroot 20099 0.0 0.5 313272 5832 ? ss 22:44 0:00 php-fpm: master process (/etc/php-fpm.conf)apache 20100 0.4 1.1 317112 11876 ? s 22:44 0:00 php-fpm: pool wwwapache 20101 0.3 1.5 319936 15316 ? s 22:44 0:00 php-fpm: pool wwwapache 20102 0.4 1.6 322244 16892 ? s 22:44 0:00 php-fpm: pool wwwapache 20103 0.4 1.5 320964 15636 ? s 22:44 0:00 php-fpm: pool wwwapache 20104 0.3 1.3 319648 14256 ? s 22:44 0:00 php-fpm: pool wwwapache 20106 0.3 1.3 319140 13696 ? s 22:45 0:00 php-fpm: pool wwwapache 20107 0.1 0.7 313776 8140 ? s 22:46 0:00 php-fpm: pool wwwroot 20109 0.0 0.0 103236 864 pts/0 s+ 22:47 0:00 grep php-fpm
可见其进程号为20099,其余进程为其子进程,而grep php-fpm是查看进程这个命令的进程。
3.6 问题:数据库的图像文件没有显示原因:php-fpm子进程的所有者:组是apache,而不是www。而nginx是运行在www用户下,故应当改为www。
编辑/etc/php-fpm.d/www.conf:
[www];user = apacheuser = www;group = apachegroup = www
再重启php-fpm服务:
# service php-fpm stopstopping php-fpm: [ ok ]# service php-fpm startstarting php-fpm: [ ok ]
查看php-fpm进程:
# ps aux | grep php-fpmroot 20208 0.0 0.5 313272 5832 ? ss 23:13 0:00 php-fpm: master process (/etc/php-fpm.conf)www 20209 0.4 1.0 316056 10388 ? s 23:13 0:00 php-fpm: pool wwwwww 20210 0.3 0.9 315020 9280 ? s 23:13 0:00 php-fpm: pool wwwwww 20211 0.4 1.0 316580 10764 ? s 23:13 0:00 php-fpm: pool wwwwww 20212 0.4 1.0 316056 10388 ? s 23:13 0:00 php-fpm: pool wwwwww 20213 0.0 0.4 313272 4872 ? s 23:13 0:00 php-fpm: pool wwwwww 20215 0.0 0.4 313272 4876 ? s 23:13 0:00 php-fpm: pool wwwroot 20217 0.0 0.0 103236 860 pts/0 s+ 23:14 0:00 grep php-fpm
可以看到php-fpm进程的进程号是20208,其子进程都以www用户身份运行,而grep php-fpm是查看进程这个命令的进程。
3.7 问题:登录总是失败,并重新返回到登录页面错误日志为:
2014-06-14 23:14:36 warning: warning (2): unknown: failed to write session data (files). please verify that the current setting of session.save_path is correct (/var/lib/php/session) in [unknown, line 0]
原因:php session目录的所有者:组是apache:apache,而不是www:www,与实际进程运行的用户身份不符。
更改php session目录的所有者:组为www:www:
# chown -r www:www /var/lib/php/session
从此,王子和公主过着没羞没臊的生活!
a. 参考资料upgrading php on centos 6.5 (final)
http://stackoverflow.com/questions/21502656/upgrading-php-on-centos-6-5-finalupgrading php 5.3.3 to 5.4.4 in centos 6.4
http://superuser.com/questions/615401/upgrading-php-5-3-3-to-5-4-4-in-centos-6-4how to upgrade php to 5.4.10 on centos 6.3
http://serverfault.com/questions/466394/how-to-upgrade-php-to-5-4-10-on-centos-6-3repository configuration - les rpm de remi
http://blog.famillecollet.com/pages/config-enbasic yum commands and how to use them
http://yum.baseurl.org/wiki/yumcommandshow do i upgrade to the latest php version in centos with yum?
http://serverfault.com/questions/456968/how-do-i-upgrade-to-the-latest-php-version-in-centos-with-yum
尽管这是从php 5.3升级到5.4,不过这是使用remi安装库。setting up php behind nginx with fastcgi
http://www.sitepoint.com/setting-up-php-behind-nginx-with-fastcgi/running multiple php versions is so easy with fastcgi
http://www.ondrejsimek.com/blog/running-multiple-php-versions-is-so-easy-with-fastcgi/build php 5.4 on centos 6.2
http://benramsey.com/blog/2012/03/build-php-54-on-centos-62/
这是关于如何从源代码编译、构建、安装php 5.4的。a better way to run php-fpm
http://mattiasgeniar.be/2014/04/09/a-better-way-to-run-php-fpm/install nginx, php 5.5 and fastcgi on centos 6
http://geekpeek.net/install-nginx-php55-fastcgi/nginx and php-fpm configuration and optimizing tips and tricks
http://www.if-not-true-then-false.com/2011/nginx-and-php-fpm-configuration-and-optimizing-tips-and-tricks/home - php-fpm
http://php-fpm.org/php: fastcgi process manager (fpm) - manual
http://php.net/manual/en/install.fpm.php
其它类似信息

推荐信息