如何在CentOS上升级php5.4至5.6?
由于CentOS的默认的php安装源版本都是5.4
以下的,如果你的项目对php版本有要求或者想升级折腾的可以参考此文升级方法,新项目新环境个人更推荐使用更牛x地php7
。
了解php5.6
的新特性可参考:
PHP5.6 New Features:http://php.net/manual/en/migration56.new-features.php
PHP5.6正式版新特性、新功能介紹:http://www.arefly.com/php-5-6-new-feature/
本教程适用的linux发行版:CentOS/RHEL 7
、CentOS/RHEL 6
、CentOS/RHEL 5
,提供PHP5.4
升级至PHP5.6
的方法。
首先查看你的php版本:
php -v
PHP 5.4.35 (cli) (built: Nov 14 2014 07:04:10) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
安装rpm升级包
注意:请选择符合你的系统版本的命令
CentOS/RHEL 7:
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
CentOS/RHEL 6:
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
CentOS/RHEL 5:
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
安装完之后我们要删除旧版php模块
# yum remove php-common
Dependencies Resolved
===================================================================================
Package Arch Version Repository Size
===================================================================================
Removing:
php-common x86_64 5.4.39-1.el6.remi @remi 7.0 M
Removing for dependencies:
php x86_64 5.4.39-1.el6.remi @remi 9.1 M
php-cli x86_64 5.4.39-1.el6.remi @remi 12 M
php-devel x86_64 5.4.39-1.el6.remi @remi 8.1 M
php-gd x86_64 5.4.39-1.el6.remi @remi 665 k
php-ldap x86_64 5.4.39-1.el6.remi @remi 119 k
php-mbstring x86_64 5.4.39-1.el6.remi @remi 2.5 M
php-mcrypt x86_64 5.4.39-1.el6.remi @remi 86 k
php-mysql x86_64 5.4.39-1.el6.remi @remi 452 k
php-pdo x86_64 5.4.39-1.el6.remi @remi 348 k
php-pear noarch 1:1.9.5-9.el6.remi @remi 2.0 M
php-process x86_64 5.4.39-1.el6.remi @remi 128 k
php-snmp x86_64 5.4.39-1.el6.remi @remi 107 k
php-xml x86_64 5.4.39-1.el6.remi @remi 626 k
Transaction Summary
===================================================================================
Remove 14 Package(s)
Installed size: 43 M
开始安装PHP5.6
# yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring
安装完成后重启Apache
# /etc/init.d/httpd restart
再次查看php版本
# php -v
PHP 5.6.8 (cli) (built: Apr 17 2015 22:49:36) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
至此,大功告成!