CentOS7使用YUM安装PHP7

安装或升级PHP版本,使用yum命令及webtatic库

卸载已安装PHP

更新之前查看当前PHP版本避免重复更新

# php -v

检查当前PHP的安装包

# yum list installed | grep php

完全移除当前PHP安装包以免起冲突

# yum remove php*

PHP 软件源

默认的yum源无法升级PHP,需要添加第三方yum源,我们选择webtatic库

CentOs 5.x

rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm

CentOs 6.x

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

CentOs 7.X

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

小提示

如果安装错误:
error: Failed dependencies:
epel-release >= 7 is needed by webtatic-release-7-3.noarch
需要先安装epel-release。

安装epel-release

通过命令:

rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

成功安装。

安装PHP7源

终端再次运行如下命令:

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装 PHP

查看yum源是否有php7.1安装包

yum list php71

安装php及相关插件
安装php7.0

yum install -y php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64 php70w-fpm

其他版本php安装
如果想安装php5.5或者5.6版本,将上面的php70w替换为php55w或者php56w就可以了。

安装php7.1

yum install -y php71w-fpm php71w-opcache php71w-cli php71w-gd php71w-imap php71w-mysqlnd php71w-mbstring php71w-mcrypt php71w-pdo php71w-pecl-apcu php71w-pecl-mongodb php71w-pecl-redis php71w-pgsql php71w-xml php71w-xmlrpc php71w-devel mod_php71w

查看当前php版本

php -v

开启php-fpm服务

systemctl start php-fpm.service
systemctl enable php-fpm.service

更多资料

https://webtatic.com/packages/php71/