Centos 6/7 升级 PHP 5.6 到 7.1/7.2

1. 检查当前安装的 PHP

查看当前 PHP 版本

php -v

查看当前 PHP 相关的安装包

yum list installed | grep php

2. 更换 RPM 源

#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

3. 停止相关服务

关闭 php-fpm 和 nginx 服务

service php-fpm stop
/usr/local/nginx/sbin/nginx -s stop

 

4. 删除已经安装的 PHP 相关包

yum remove php*

5. 安装新版本 PHP

php 7.0/7.1/7.2 分别表示为 70w/71w/72w

CentOs 7.x 的 RPM 源中有 7.2

yum install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-fpm php71w-gd php71w-mbstring php71w-mysqlnd php71w-opcache php71w-pdo php71w-xml php71w-ldap php71w-mcrypt
BashCopy

6. 重新启动相关服务

service php-fpm start
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

systemctl enable php-fpm.service【开机自启动】

7. 再次检查版本

php -v

参考

你可能感兴趣的:(php)