Upgrade php5.3 to php5.6 under centos

Talk is cheap, show me the code.

View and delete the original php5.3

Check out the original php version:

php -V
  • 1
  • 2

Check out the installed php packages:

yum list installed | grep php
  • 1
  • 2

You can see the original installation package as follows:

php-common.x86_64 0:5.3.3-38.el6   
php-gd.x86_64 0:5.3.3-38.el6        
php-ldap.x86_64 0:5.3.3-38.el6          
php-mysql.x86_64 0:5.3.3-38.el6    
php-odbc.x86_64 0:5.3.3-38.el6      
php-pdo.x86_64 0:5.3.3-38.el6           
php-pear.noarch 1:1.9.4-4.el6      
php-pecl-apc.x86_64 0:3.1.9-2.el6   
php-pecl-memcache.x86_64 0:3.0.5-4.el6  
php-pgsql.x86_64 0:5.3.3-38.el6    
php-soap.x86_64 0:5.3.3-38.el6      
php-xml.x86_64 0:5.3.3-38.el6           
php-xmlrpc.x86_64 0:5.3.3-38.el6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

All are 5.3.3-38.el6 version.

If the original 5.3 package is not deleted, a conflicting error will be reported when installing the php5.6 package.

Remove packages for 5.3:

yum remove php.cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mysql.x86_64 php-odbc.x86_64 php-pdo.x86_64 php-pear.noarch php-pecl-apc.x86_64 php-pecl-memcache.x86_64 php-pgsql.x86_64 php-soap.x86_64 php-xml.x86_64 php-xmlrpc.x86_64
  • 1
  • 2

After deleting, you can confirm whether the deletion has been completed:

yum list installed | grep php
  • 1
  • 2

The result should be empty.

Install php5.6 package

Since the original rpm of centos 6.* does not contain the resources of the 5.6 package, it is necessary to install the installation source of importing php first:

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
  • 1
  • 2

Then install the 5.6 related packages:

yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-odbc.x86_64 php56w-xml.x86_64 php56w-xmlrpc.x86_64 php56w-soap.x86_64
  • 1
  • 2

After all installations are successful, please confirm:

yum list installed | grep php
  • 1
  • 2

The result is as follows:

php56w.x86_64            5.6.27-1.w6    @webtatic                               
php56w-cli.x86_64        5.6.27-1.w6    @webtatic                               
php56w-common.x86_64     5.6.27-1.w6    @webtatic                               
php56w-gd.x86_64         5.6.27-1.w6    @webtatic                               
php56w-ldap.x86_64       5.6.27-1.w6    @webtatic                               
php56w-mbstring.x86_64   5.6.27-1.w6    @webtatic                               
php56w-mysql.x86_64      5.6.27-1.w6    @webtatic                               
php56w-odbc.x86_64       5.6.27-1.w6    @webtatic                               
php56w-pdo.x86_64        5.6.27-1.w6    @webtatic                               
php56w-soap.x86_64       5.6.27-1.w6    @webtatic                               
php56w-xml.x86_64        5.6.27-1.w6    @webtatic                               
php56w-xmlrpc.x86_64     5.6.27-1.w6    @webtatic
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

Restart php-fpm:

/usr/local/php/sbin/php-fpm restart
  • 1
  • 2

Then execute:

php -v
  • 1
  • 2

5.6 should be displayed.

The upgrade is complete.

However, there is a question:

the version of php -v executed directly on the server is 5.6, but an info.php is written on the nginx server with the following content:

<?php
    phpinfo();
?>
  • 1
  • 2
  • 3
  • 4

Then visit: http://ip:port/info.php in the browser, but the page displayed is still the old 5.3 version. This issue has not yet been clarified.

For the above questions, the tracking progress is as follows:

although the dependency package of php installed is deleted above, but the old php version itself has not been deleted, that is to say, there are two versions of php on centos. After upgrading the php dependency package, execute php -v only However, the path accessed by the system defaults to the 5.6 version of the package, but when accessed through other applications, such as nginx, the old 5.2 version of php is still accessed.

The inspection process is as follows: 
Execute php -v: 5.6

View all versions of php on the system:

find / -name php
  • 1
  • 2

The following two commands can be found in the displayed results:

/usr/local/php/bin/php
/etc/bin/php
  • 1
  • 2
  • 3

分别执行 /usr/local/php/bin/php -v 和 /etc/bin/php -v 可以看到,一个是5.2版本,一个是5.6版本,这就是为什么上面php -v 看到的是5.6版本,而phpinfo看到的是5.2版本的直接原因。
根本原因:通过nginx访问php请求,nginx转发到127.0.0.1:9000,监听9000端口的php-fpm接收到请求后,将请求转交给对应的php解释器进行处理,也就是说使用的是哪个版本的php是由php-fpm决定,而php-fpm只是php的一个补丁,通过编译安装php时configure时加上参数 –enable-fpm 安装php-fpm,所以安装php时就已经决定了php-fpm调用的是哪一个版本的php,如果需要改变使用的php版本,只能重新下载更新版本的php源代码,然后重新编译安装带上–enable-fpm参数,这样才能成功改变phpinfo()显示的版本。

重新安装php5.6的方法参考linux安装nginx和mysql和php.md。

另外,想要找到系统采用的当前php.ini配置文件的话,可以通过下面的方式查找:

find / -name php.ini
  • 1
  • 2

这样可能会显示多个php.ini路径,然后执行如下命令可以获取当前被系统采用的php.ini配置文件:

php -i | grep php.ini

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326143965&siteId=291194637