摘要:本文记录了在CentOS 6.3上,把PHP从5.4.8升级到5.5.13的过程。
在我做的一个项目中,最近我对生产服务器上的一系列系统软件进行了升级,包括Git、Nginx、MySQL和PHP。这篇文章讲的是升级PHP的过程,其他软件的升级,可见下面列出的文章。
在我加入这个项目之前,服务器上的PHP已经安装设置好了,我只是正常使用而已。现在过去1年了,所有的开发工作都告一段落,有时间升级服务器上的软件了。升级这种事情是应当经常做的,倒不是为了追最新版本,而是当正式版本发放出来的时候,应该及时更新, 以便获得最新的更正、补丁,避免服务器上的漏洞,减少安全隐患。
升级是在今年6月13-14日进行的,到今天才有空做个记录,便于日后参考。
计划就是预案,就是事先的准备(包括心理上的)、更明细的步骤、对各种情况及对意外的对策,当然,我们不可能面面俱到,预测一切,不然就成神了,所以要随时准备脱稿演出,think out of the box。
计划要有针对性,所以要先”踩点儿“。
通过在系统上,用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 -<span>v PHP </span><span>5.4</span>.<span>8</span> (cli) (built: Nov <span>13</span> <span>2012</span> <span>00</span>:<span>08</span>:<span>08</span><span>) Copyright (c) </span><span>1997</span>-<span>2012</span><span> The PHP Group Zend Engine v2.</span><span>4.0</span>, Copyright (c) <span>1998</span>-<span>2012</span> Zend Tehnologies
再查看PHP-FPM的运行情况。那两天看文档,我才知道有PHP-FPM(FastCGI Process Manager)这么个东西,在5.4之后已经包括在PHP之中了,详见参考资料[]13][14]。
查看PHP-FPM使用的端口:
# netstat -ntpul | <span>grep</span> php-<span>fpm tcp </span><span>0</span> <span>0</span> <span>127.0</span>.<span>0.1</span>:<span>9000</span> <span>0.0</span>.<span>0.0</span>:* LISTEN <span>2881</span>/php-fpm
查看PHP-FPM的进程:
# <span>ps</span> aux | <span>grep</span> php-<span>fpm USER PID </span>%CPU %<span>MEM VSZ RSS TTY STAT START TIME COMMAND root </span><span>2881</span> <span>0.0</span> <span>0.2</span> <span>204172</span> <span>2064</span> ? Ss <span>2013</span> <span>38</span>:<span>09</span> php-fpm: master process (/usr/local/php/etc/php-<span>fpm.conf) www </span><span>18982</span> <span>0.0</span> <span>1.4</span> <span>212796</span> <span>14816</span> ? S <span>19</span>:<span>12</span> <span>0</span>:<span>03</span> php-<span>fpm: pool www www </span><span>18983</span> <span>0.0</span> <span>1.4</span> <span>211996</span> <span>14572</span> ? S <span>19</span>:<span>13</span> <span>0</span>:<span>03</span> php-<span>fpm: pool www www </span><span>18984</span> <span>0.0</span> <span>1.4</span> <span>212276</span> <span>14876</span> ? S <span>19</span>:<span>13</span> <span>0</span>:<span>03</span> php-<span>fpm: pool www root </span><span>19144</span> <span>0.0</span> <span>0.0</span> <span>103236</span> <span>864</span> pts/<span>0</span> S+ <span>23</span>:<span>29</span> <span>0</span>:<span>00</span> <span>grep</span> php-fpm
查看PHP-FPM的版本:
# /usr/local/php/sbin/php-fpm -<span>v PHP </span><span>5.4</span>.<span>8</span> (fpm-fcgi) (built: Nov <span>13</span> <span>2012</span> <span>00</span>:<span>15</span>:<span>58</span><span>) Copyright (c) </span><span>1997</span>-<span>2012</span><span> The PHP Group Zend Engine v2.</span><span>4.0</span>, Copyright (c) <span>1998</span>-<span>2012</span> Zend Technologies
查看上次系统启动的时间,这是怕安装的东西没重启而没有生效:
# <span>who</span> -<span>b system boot </span><span>2013</span>-<span>01</span>-<span>04</span> <span>01</span>:<span>07</span><span> # </span><span>last</span><span> reboot reboot system boot </span><span>2.6</span>.<span>32</span>-<span>279.14</span>.<span>1</span>. Fri Jan <span>4</span> <span>01</span>:<span>07</span> - <span>20</span>:<span>36</span> (<span>526</span>+<span>19</span>:<span>29</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Mon Nov <span>12</span> <span>17</span>:<span>53</span> - <span>20</span>:<span>36</span> (<span>579</span>+<span>02</span>:<span>42</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Thu May <span>10</span> <span>17</span>:<span>12</span> - <span>17</span>:<span>13</span> (<span>00</span>:<span>01</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Wed May <span>9</span> <span>15</span>:<span>31</span> - <span>15</span>:<span>36</span> (<span>00</span>:<span>04</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Wed May <span>9</span> <span>15</span>:<span>03</span> - <span>15</span>:<span>29</span> (<span>00</span>:<span>26</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Wed May <span>9</span> <span>10</span>:<span>09</span> - <span>12</span>:<span>26</span> (<span>02</span>:<span>16</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Thu May <span>3</span> <span>17</span>:<span>23</span> - <span>17</span>:<span>25</span> (<span>00</span>:<span>02</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Fri May <span>4</span> <span>01</span>:<span>17</span> - <span>17</span>:<span>22</span> (-<span>7</span>:-<span>54</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Fri Apr <span>20</span> <span>21</span>:<span>33</span> - <span>17</span>:<span>22</span> (<span>12</span>+<span>19</span>:<span>48</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Sat Apr <span>21</span> <span>03</span>:<span>39</span> - <span>17</span>:<span>22</span> (<span>12</span>+<span>13</span>:<span>42</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Fri Apr <span>20</span> <span>18</span>:<span>02</span> - <span>17</span>:<span>22</span> (<span>12</span>+<span>23</span>:<span>19</span><span>) reboot system boot </span><span>2.6</span>.<span>32</span>-<span>220.13</span>.<span>1</span>. Thu Apr <span>19</span> <span>19</span>:<span>51</span> - <span>17</span>:<span>59</span> (<span>22</span>:<span>07</span>)
其实这种担心是多余的,因为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。下面是我尝试的结果:
# <span>yum</span><span> update php Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile </span>* base: mirrors.<span>163</span><span>.com </span>*<span> epel: mirrors.hust.edu.cn </span>* extras: mirrors.<span>163</span><span>.com </span>*<span> remi: mirrors.hustunique.com </span>* remi-<span>php55: mirrors.hustunique.com </span>* updates: mirrors.<span>163</span><span>.com Setting up Update Process Package(s) php available, but not installed. No Packages marked </span><span>for</span> Update
可见,yum没有找到已经安装的php包,所以没什么可以升级的。孤独的编译安装,没人待见,看来要在角落里终老一生了。
经过在几个CakePHP、PHP相关的QQ群里,向其他朋友的请教和讨论,(此处略去15000字),其实这是和上面的”踩点儿“互相掺杂在一起进行的。在这里要特别感谢CakePHP群中的Christian和严谨的PHP HHVM MySQL群中的Linux 管理员(Freax)两位朋友。最终在朋友们的帮助下形成了下面的计划要点:
前期的调研、计划,花了差不多2天时间,而之后的安装、配置,也就用了3-4个小时。
根据这两天读的文档,确定使用remi安装库,使用yum来安装PHP 5.5.13。
下面的操作依据参考资料[4]:
# <span>wget</span> http:<span>//</span><span>dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm</span> # <span>wget</span> http:<span>//</span><span>rpms.famillecollet.com/enterprise/remi-release-6.rpm</span> # rpm -Uvh remi-release-<span>6</span>*.rpm epel-release-<span>6</span>*.rpm
从之前PHP 5.4.8下phpinfo()的输出,知道了旧的PHP 5.4.8上安装的PHP扩展,这样确定了下面需要安装的包(命令yum install之后的参数):
# <span>yum</span> <span>install</span> php php-fpm php-gd php-mysqlnd php-mcrypt php-mbstring php-<span>pdo Dependencies Resolved </span>================================================================================<span> Package Arch Version Repository Size </span>================================================================================<span> Installing: libjpeg</span>-turbo x86_64 <span>1.2</span>.<span>1</span>-<span>3</span>.el6_5 updates <span>174</span><span> k replacing libjpeg.x86_64 6b</span>-<span>46</span><span>.el6 libjpeg</span>-turbo-devel x86_64 <span>1.2</span>.<span>1</span>-<span>3</span>.el6_5 updates <span>96</span><span> k replacing libjpeg</span>-devel.x86_64 6b-<span>46</span><span>.el6 php x86_64 </span><span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>2.6</span><span> M php</span>-fpm x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>1.3</span><span> M php</span>-gd x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>69</span><span> k php</span>-mbstring x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>958</span><span> k php</span>-mcrypt x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>40</span><span> k php</span>-mysqlnd x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>261</span><span> k php</span>-pdo x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>109</span><span> k Installing </span><span>for</span><span> dependencies: apr</span>-util-ldap x86_64 <span>1.3</span>.<span>9</span>-<span>3</span>.el6_0.<span>1</span> base <span>15</span><span> k fontconfig x86_64 </span><span>2.8</span>.<span>0</span>-<span>3</span>.el6 base <span>186</span><span> k gd</span>-<span>last</span> x86_64 <span>2.1</span>.<span>0</span>-<span>2</span>.el6.remi remi <span>129</span><span> k httpd x86_64 </span><span>2.2</span>.<span>15</span>-<span>30</span>.el6.centos updates <span>821</span><span> k httpd</span>-tools x86_64 <span>2.2</span>.<span>15</span>-<span>30</span>.el6.centos updates <span>73</span><span> k libX11 x86_64 </span><span>1.5</span>.<span>0</span>-<span>4</span>.el6 base <span>584</span><span> k libX11</span>-common noarch <span>1.5</span>.<span>0</span>-<span>4</span>.el6 base <span>192</span><span> k libXau x86_64 </span><span>1.0</span>.<span>6</span>-<span>4</span>.el6 base <span>24</span><span> k libXpm x86_64 </span><span>3.5</span>.<span>10</span>-<span>2</span>.el6 base <span>51</span><span> k libmcrypt x86_64 </span><span>2.5</span>.<span>8</span>-<span>9</span>.el6 epel <span>96</span><span> k libtiff x86_64 </span><span>3.9</span>.<span>4</span>-<span>10</span>.el6_5 updates <span>343</span><span> k libxcb x86_64 </span><span>1.8</span>.<span>1</span>-<span>1</span>.el6 base <span>110</span><span> k libxslt x86_64 </span><span>1.1</span>.<span>26</span>-<span>2</span>.el6_3.<span>1</span> base <span>452</span><span> k mailcap noarch </span><span>2.1</span>.<span>31</span>-<span>2</span>.el6 base <span>27</span><span> k php</span>-cli x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>2.5</span><span> M php</span>-common x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>1.0</span><span> M php</span>-pear noarch <span>1</span>:<span>1.9</span>.<span>4</span>-<span>28</span>.el6.remi remi <span>373</span><span> k php</span>-pecl-jsonc x86_64 <span>1.3</span>.<span>5</span>-<span>1</span>.el6.remi.<span>5.5</span> remi-php55 <span>46</span><span> k php</span>-pecl-<span>zip</span> x86_64 <span>1.12</span>.<span>4</span>-<span>1</span>.el6.remi.<span>5.5</span> remi-php55 <span>269</span><span> k php</span>-process x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>54</span><span> k php</span>-xml x86_64 <span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi remi-php55 <span>206</span><span> k t1lib x86_64 </span><span>5.1</span>.<span>2</span>-<span>6</span>.el6_2.<span>1</span> base <span>160</span><span> k Transaction Summary </span>================================================================================<span> Install </span><span>31</span> Package(s)
yum自动计算出需要的依赖安装包,总共有31个安装包需要下载、安装。
下面询问是否继续下载,回答y,并按回车即可继续:
Total download size: <span>13</span><span> M Is this ok [y</span>/<span>N]: y Downloading Packages: (</span><span>1</span>/<span>31</span>): apr-util-ldap-<span>1.3</span>.<span>9</span>-<span>3</span>.el6_0.<span>1</span>.x86_64.rpm | <span>15</span> kB <span>00</span>:<span>00</span><span> (</span><span>2</span>/<span>31</span>): fontconfig-<span>2.8</span>.<span>0</span>-<span>3</span>.el6.x86_64.rpm | <span>186</span> kB <span>00</span>:<span>00</span><span> (</span><span>3</span>/<span>31</span>): gd-<span>last</span>-<span>2.1</span>.<span>0</span>-<span>2</span>.el6.remi.x86_64.rpm | <span>129</span> kB <span>00</span>:<span>00</span><span> (</span><span>4</span>/<span>31</span>): httpd-<span>2.2</span>.<span>15</span>-<span>30</span>.el6.centos.x86_64.rpm | <span>821</span> kB <span>00</span>:<span>00</span><span> (</span><span>5</span>/<span>31</span>): httpd-tools-<span>2.2</span>.<span>15</span>-<span>30</span>.el6.centos.x86_64.rpm | <span>73</span> kB <span>00</span>:<span>00</span><span> (</span><span>6</span>/<span>31</span>): libX11-<span>1.5</span>.<span>0</span>-<span>4</span>.el6.x86_64.rpm | <span>584</span> kB <span>00</span>:<span>00</span><span> (</span><span>7</span>/<span>31</span>): libX11-common-<span>1.5</span>.<span>0</span>-<span>4</span>.el6.noarch.rpm | <span>192</span> kB <span>00</span>:<span>00</span><span> (</span><span>8</span>/<span>31</span>): libXau-<span>1.0</span>.<span>6</span>-<span>4</span>.el6.x86_64.rpm | <span>24</span> kB <span>00</span>:<span>00</span><span> (</span><span>9</span>/<span>31</span>): libXpm-<span>3.5</span>.<span>10</span>-<span>2</span>.el6.x86_64.rpm | <span>51</span> kB <span>00</span>:<span>00</span><span> (</span><span>10</span>/<span>31</span>): libjpeg-turbo-<span>1.2</span>.<span>1</span>-<span>3</span>.el6_5.x86_64.rpm | <span>174</span> kB <span>00</span>:<span>00</span><span> (</span><span>11</span>/<span>31</span>): libjpeg-turbo-devel-<span>1.2</span>.<span>1</span>-<span>3</span>.el6_5.x86_64.rpm | <span>96</span> kB <span>00</span>:<span>00</span><span> (</span><span>12</span>/<span>31</span>): libmcrypt-<span>2.5</span>.<span>8</span>-<span>9</span>.el6.x86_64.rpm | <span>96</span> kB <span>00</span>:<span>00</span><span> (</span><span>13</span>/<span>31</span>): libtiff-<span>3.9</span>.<span>4</span>-<span>10</span>.el6_5.x86_64.rpm | <span>343</span> kB <span>00</span>:<span>00</span><span> (</span><span>14</span>/<span>31</span>): libxcb-<span>1.8</span>.<span>1</span>-<span>1</span>.el6.x86_64.rpm | <span>110</span> kB <span>00</span>:<span>00</span><span> (</span><span>15</span>/<span>31</span>): libxslt-<span>1.1</span>.<span>26</span>-<span>2</span>.el6_3.<span>1</span>.x86_64.rpm | <span>452</span> kB <span>00</span>:<span>00</span><span> (</span><span>16</span>/<span>31</span>): mailcap-<span>2.1</span>.<span>31</span>-<span>2</span>.el6.noarch.rpm | <span>27</span> kB <span>00</span>:<span>00</span><span> (</span><span>17</span>/<span>31</span>): php-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>2.6</span> MB <span>00</span>:<span>00</span><span> (</span><span>18</span>/<span>31</span>): php-cli-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>2.5</span> MB <span>00</span>:<span>00</span><span> (</span><span>19</span>/<span>31</span>): php-common-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>1.0</span> MB <span>00</span>:<span>00</span><span> (</span><span>20</span>/<span>31</span>): php-fpm-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>1.3</span> MB <span>00</span>:<span>00</span><span> (</span><span>21</span>/<span>31</span>): php-gd-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>69</span> kB <span>00</span>:<span>00</span><span> (</span><span>22</span>/<span>31</span>): php-mbstring-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>958</span> kB <span>00</span>:<span>00</span><span> (</span><span>23</span>/<span>31</span>): php-mcrypt-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>40</span> kB <span>00</span>:<span>00</span><span> (</span><span>24</span>/<span>31</span>): php-mysqlnd-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>261</span> kB <span>00</span>:<span>00</span><span> (</span><span>25</span>/<span>31</span>): php-pdo-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>109</span> kB <span>00</span>:<span>00</span><span> (</span><span>26</span>/<span>31</span>): php-pear-<span>1.9</span>.<span>4</span>-<span>28</span>.el6.remi.noarch.rpm | <span>373</span> kB <span>00</span>:<span>00</span><span> (</span><span>27</span>/<span>31</span>): php-pecl-jsonc-<span>1.3</span>.<span>5</span>-<span>1</span>.el6.remi.<span>5.5</span>.x86_64.rpm | <span>46</span> kB <span>00</span>:<span>00</span><span> (</span><span>28</span>/<span>31</span>): php-pecl-<span>zip</span>-<span>1.12</span>.<span>4</span>-<span>1</span>.el6.remi.<span>5.5</span>.x86_64.rpm | <span>269</span> kB <span>00</span>:<span>00</span><span> (</span><span>29</span>/<span>31</span>): php-process-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>54</span> kB <span>00</span>:<span>00</span><span> (</span><span>30</span>/<span>31</span>): php-xml-<span>5.5</span>.<span>13</span>-<span>3</span>.el6.remi.x86_64.rpm | <span>206</span> kB <span>00</span>:<span>00</span><span> (</span><span>31</span>/<span>31</span>): t1lib-<span>5.1</span>.<span>2</span>-<span>6</span>.el6_2.<span>1</span>.x86_64.rpm | <span>160</span> kB <span>00</span>:<span>00</span> --------------------------------------------------------------------------------<span> Total </span><span>3.6</span> MB/s | <span>13</span> MB <span>00</span>:<span>03</span>
之后还有一些Is this ok [y/N]:的问题,一律回答y。经过一轮问答和安装,最后完成时的小结为:
<span>Installed: libjpeg</span>-turbo.x86_64 <span>0</span>:<span>1.2</span>.<span>1</span>-<span>3</span><span>.el6_5 libjpeg</span>-turbo-devel.x86_64 <span>0</span>:<span>1.2</span>.<span>1</span>-<span>3</span><span>.el6_5 php.x86_64 </span><span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-fpm.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-gd.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-mbstring.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-mcrypt.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-mysqlnd.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-pdo.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi Dependency Installed: apr</span>-util-ldap.x86_64 <span>0</span>:<span>1.3</span>.<span>9</span>-<span>3</span>.el6_0.<span>1</span><span> fontconfig.x86_64 </span><span>0</span>:<span>2.8</span>.<span>0</span>-<span>3</span><span>.el6 gd</span>-<span>last</span>.x86_64 <span>0</span>:<span>2.1</span>.<span>0</span>-<span>2</span><span>.el6.remi httpd.x86_64 </span><span>0</span>:<span>2.2</span>.<span>15</span>-<span>30</span><span>.el6.centos httpd</span>-tools.x86_64 <span>0</span>:<span>2.2</span>.<span>15</span>-<span>30</span><span>.el6.centos libX11.x86_64 </span><span>0</span>:<span>1.5</span>.<span>0</span>-<span>4</span><span>.el6 libX11</span>-common.noarch <span>0</span>:<span>1.5</span>.<span>0</span>-<span>4</span><span>.el6 libXau.x86_64 </span><span>0</span>:<span>1.0</span>.<span>6</span>-<span>4</span><span>.el6 libXpm.x86_64 </span><span>0</span>:<span>3.5</span>.<span>10</span>-<span>2</span><span>.el6 libmcrypt.x86_64 </span><span>0</span>:<span>2.5</span>.<span>8</span>-<span>9</span><span>.el6 libtiff.x86_64 </span><span>0</span>:<span>3.9</span>.<span>4</span>-<span>10</span><span>.el6_5 libxcb.x86_64 </span><span>0</span>:<span>1.8</span>.<span>1</span>-<span>1</span><span>.el6 libxslt.x86_64 </span><span>0</span>:<span>1.1</span>.<span>26</span>-<span>2</span>.el6_3.<span>1</span><span> mailcap.noarch </span><span>0</span>:<span>2.1</span>.<span>31</span>-<span>2</span><span>.el6 php</span>-cli.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-common.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-pear.noarch <span>1</span>:<span>1.9</span>.<span>4</span>-<span>28</span><span>.el6.remi php</span>-pecl-jsonc.x86_64 <span>0</span>:<span>1.3</span>.<span>5</span>-<span>1</span>.el6.remi.<span>5.5</span><span> php</span>-pecl-<span>zip</span>.x86_64 <span>0</span>:<span>1.12</span>.<span>4</span>-<span>1</span>.el6.remi.<span>5.5</span><span> php</span>-process.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi php</span>-xml.x86_64 <span>0</span>:<span>5.5</span>.<span>13</span>-<span>3</span><span>.el6.remi t1lib.x86_64 </span><span>0</span>:<span>5.1</span>.<span>2</span>-<span>6</span>.el6_2.<span>1</span><span> Replaced: libjpeg.x86_64 </span><span>0</span>:6b-<span>46</span>.el6 libjpeg-devel.x86_64 <span>0</span>:6b-<span>46</span><span>.el6 Complete</span>!
因为使用yum安装,安装过程已经拷贝好了PHP-FPM的服务daemon,只需确保PHP-FPM服务能在系统重启时自动启动就行了:
# chkconfig php-fpm on
查看PHP-FPM服务的自启动状态:
# chkconfig --list php-<span>fpm php</span>-fpm <span>0</span>:off <span>1</span>:off <span>2</span>:on <span>3</span>:on <span>4</span>:on <span>5</span>:on <span>6</span>:off
正确。
查看PHP-FPM 5.4.8的进程:
# <span>ps</span> aux | <span>grep</span> php-<span>fpm root </span><span>2881</span> <span>0.0</span> <span>0.1</span> <span>204172</span> <span>1972</span> ? Ss <span>2013</span> <span>38</span>:<span>13</span> php-fpm: master process (/usr/local/php/etc/php-<span>fpm.conf) www </span><span>19378</span> <span>0.0</span> <span>1.4</span> <span>212764</span> <span>14736</span> ? S <span>10</span>:<span>30</span> <span>0</span>:<span>14</span> php-<span>fpm: pool www www </span><span>19379</span> <span>0.0</span> <span>1.5</span> <span>213352</span> <span>15888</span> ? S <span>10</span>:<span>32</span> <span>0</span>:<span>13</span> php-<span>fpm: pool www www </span><span>19657</span> <span>0.0</span> <span>1.3</span> <span>212076</span> <span>13964</span> ? S <span>18</span>:<span>45</span> <span>0</span>:<span>02</span> php-<span>fpm: pool www root </span><span>20083</span> <span>0.0</span> <span>0.0</span> <span>103236</span> <span>864</span> pts/<span>0</span> S+ <span>22</span>:<span>40</span> <span>0</span>:<span>00</span> <span>grep</span> 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进程:
# <span>kill</span> -TERM <span>2881</span>
再次查看PHP-FPM的进程:
# <span>ps</span> aux | <span>grep</span> php-<span>fpm root </span><span>20087</span> <span>0.0</span> <span>0.0</span> <span>103236</span> <span>864</span> pts/<span>0</span> S+ <span>22</span>:<span>43</span> <span>0</span>:<span>00</span> <span>grep</span> php-fpm
已经没有PHP-FPM的进程了,唯一剩下的grep php-fpm是查看进程这个命令的进程。
PHP-FPM的配置,我遵照的是参考资料[10],这是一个分级结构的配置文件,多个配置文件各司其职,便于更换配置,启用、停止配置的各模块也更容易。
启动php-fpm服务:
# service php-<span>fpm start Starting php</span>-fpm: [ OK ]
顺利启动。
再查看其进程:
# <span>ps</span> aux | <span>grep</span> php-<span>fpm root </span><span>20099</span> <span>0.0</span> <span>0.5</span> <span>313272</span> <span>5832</span> ? Ss <span>22</span>:<span>44</span> <span>0</span>:<span>00</span> php-fpm: master process (/etc/php-<span>fpm.conf) apache </span><span>20100</span> <span>0.4</span> <span>1.1</span> <span>317112</span> <span>11876</span> ? S <span>22</span>:<span>44</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www apache </span><span>20101</span> <span>0.3</span> <span>1.5</span> <span>319936</span> <span>15316</span> ? S <span>22</span>:<span>44</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www apache </span><span>20102</span> <span>0.4</span> <span>1.6</span> <span>322244</span> <span>16892</span> ? S <span>22</span>:<span>44</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www apache </span><span>20103</span> <span>0.4</span> <span>1.5</span> <span>320964</span> <span>15636</span> ? S <span>22</span>:<span>44</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www apache </span><span>20104</span> <span>0.3</span> <span>1.3</span> <span>319648</span> <span>14256</span> ? S <span>22</span>:<span>44</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www apache </span><span>20106</span> <span>0.3</span> <span>1.3</span> <span>319140</span> <span>13696</span> ? S <span>22</span>:<span>45</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www apache </span><span>20107</span> <span>0.1</span> <span>0.7</span> <span>313776</span> <span>8140</span> ? S <span>22</span>:<span>46</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www root </span><span>20109</span> <span>0.0</span> <span>0.0</span> <span>103236</span> <span>864</span> pts/<span>0</span> S+ <span>22</span>:<span>47</span> <span>0</span>:<span>00</span> <span>grep</span> php-fpm
可见其进程号为20099,其余进程为其子进程,而grep php-fpm是查看进程这个命令的进程。
原因:PHP-FPM子进程的所有者:组是apache,而不是www。而Nginx是运行在www用户下,故应当改为www。
编辑/etc/php-fpm.d/www.conf:
<span>[</span><span>www</span><span>]</span> <span>;</span><span>user = apache</span> user =<span> www </span><span>;</span><span>group = apache</span> group = www
再重启php-fpm服务:
# service php-<span>fpm stop Stopping php</span>-<span>fpm: [ OK ] # service php</span>-<span>fpm start Starting php</span>-fpm: [ OK ]
查看php-fpm进程:
# <span>ps</span> aux | <span>grep</span> php-<span>fpm root </span><span>20208</span> <span>0.0</span> <span>0.5</span> <span>313272</span> <span>5832</span> ? Ss <span>23</span>:<span>13</span> <span>0</span>:<span>00</span> php-fpm: master process (/etc/php-<span>fpm.conf) www </span><span>20209</span> <span>0.4</span> <span>1.0</span> <span>316056</span> <span>10388</span> ? S <span>23</span>:<span>13</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www www </span><span>20210</span> <span>0.3</span> <span>0.9</span> <span>315020</span> <span>9280</span> ? S <span>23</span>:<span>13</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www www </span><span>20211</span> <span>0.4</span> <span>1.0</span> <span>316580</span> <span>10764</span> ? S <span>23</span>:<span>13</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www www </span><span>20212</span> <span>0.4</span> <span>1.0</span> <span>316056</span> <span>10388</span> ? S <span>23</span>:<span>13</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www www </span><span>20213</span> <span>0.0</span> <span>0.4</span> <span>313272</span> <span>4872</span> ? S <span>23</span>:<span>13</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www www </span><span>20215</span> <span>0.0</span> <span>0.4</span> <span>313272</span> <span>4876</span> ? S <span>23</span>:<span>13</span> <span>0</span>:<span>00</span> php-<span>fpm: pool www root </span><span>20217</span> <span>0.0</span> <span>0.0</span> <span>103236</span> <span>860</span> pts/<span>0</span> S+ <span>23</span>:<span>14</span> <span>0</span>:<span>00</span> <span>grep</span> php-fpm
可以看到PHP-FPM进程的进程号是20208,其子进程都以www用户身份运行,而grep php-fpm是查看进程这个命令的进程。
错误日志为:
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 <span>[</span><span>Unknown, line 0</span><span>]</span>
原因:PHP session目录的所有者:组是apache:apache,而不是www:www,与实际进程运行的用户身份不符。
更改PHP session目录的所有者:组为www:www:
# chown -R www:www /var/lib/php/session
从此,王子和公主过着没羞没臊的生活!
问题人家说的很清楚了:
Error: Missing Dependency: php-api = 20041225 is needed by package php-sqlite3-0.4-1.mf.i386 (installed)
建议人家也给你了:
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest
你缺少包:php-api
centos5源里面php默认最高就是5.2
如果你想用php5.3。又不想自己编译安装在某个普通用户下面(切勿直接在root下编译安装替换系统的,会有很多问题的)
那还有一个选择。就是安装php53不过如果想装好,可能得先把php卸载掉。
在root用户下
yum remove php
然后再安装php53及所有相关组件
yum install php53*