yum升级php到php7

https://www.51anidea.com/forum.php?mod=viewthread&tid=1255
(出处: Linux教程网)

一、环境
CentOS 7
php版本:5.4.16

二、升级方法
本文介绍升级到php7的方法。

安装源:
#rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装php7:
#yum install php70w

如果出现以下报错:
Error: php70w-common conflicts with php-common-5.4.16-46.el7.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
看报错信息,故障原因是安装的php7与旧版本的php-common-5.4.16-46.el7.x86_64冲突了。php-common-5.4.16-46.el7.x86_64 是旧版本的php包。所以应该卸载它。

卸载 php-common-5.4.16-46.el7.x86_64:
#rpm -e php-common-5.4.16-46.el7.x86_64

如果出现如下报错:


error: Failed dependencies:
php-common(x86-64) = 5.4.16-46.el7 is needed by (installed) php-cli-5.4.16-46.el7.x86_64
php-common(x86-64) = 5.4.16-46.el7 is needed by (installed) php-pdo-5.4.16-46.el7.x86_64
php-common(x86-64) = 5.4.16-46.el7 is needed by (installed) php-5.4.16-46.el7.x86_64

看报错信息,故障原因是,要卸载的php-common-5.4.16-46.el7.x86_64 被 php-cli-5.4.16-46.el7.x86_64、php-pdo-5.4.16-46.el7.x86_64、php-5.4.16-46.el7.x86_64 这3个包依赖。这3个包都是旧版本的php包。所以就把这3个包一起卸载了:
#rpm -e php-common-5.4.16-46.el7.x86_64 php-cli-5.4.16-46.el7.x86_64 php-pdo-5.4.16-46.el7.x86_64 php-5.4.16-46.el7.x86_64

如果又出现如下报错:
error: Failed dependencies:
php-pdo(x86-64) = 5.4.16-46.el7 is needed by (installed) php-mysql-5.4.16-46.el7.x86_64

同样,要卸载的其中一个包被php-mysql-5.4.16-46.el7.x86_64 这个包依赖,php-mysql-5.4.16-46.el7.x86_64 是旧版本的php扩展包,所以也把它加入卸载的队伍:
#rpm -e php-common-5.4.16-46.el7.x86_64 php-cli-5.4.16-46.el7.x86_64 php-pdo-5.4.16-46.el7.x86_64 php-5.4.16-46.el7.x86_64 php-mysql-5.4.16-46.el7.x86_64

可能会出现以下警告信息:
warning: /etc/php.ini saved as /etc/php.ini.rpmsave

这个就不用管了。

再次执行命令:
#yum install php70w
终于成功安装上了。

再把php-mysql这个扩展包也更新了:
#yum install php70w-mysql

三、验证

执行以下命令检查php的版本:
#php -v
输出如下信息:PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

证明php已经成功更新到php7。

你可能感兴趣的:(yum升级php到php7)