预先准备工作:
1.查看系统版本
lsb_release -a
例如:Description: CentOS Linux release 7.6.1810 (Core)
2.更新之前查看当前PHP版本避免重复更新
php -v
查询结果
PHP 5.6.38 (cli) (built: Sep 15 2018 08:16:33)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
3.检查当前PHP的安装包
yum list installed |grep php
查询结果:
php56w-cli.x86_64 5.6.38-1.w7 @webtatic
php56w-common.x86_64 5.6.38-1.w7 @webtatic
php56w-devel.x86_64 5.6.38-1.w7 @webtatic
php56w-fpm.x86_64 5.6.38-1.w7 @webtatic
php56w-gd.x86_64 5.6.38-1.w7 @webtatic
php56w-intl.x86_64 5.6.38-1.w7 @webtatic
php56w-mbstring.x86_64 5.6.38-1.w7 @webtatic
php56w-mcrypt.x86_64 5.6.38-1.w7 @webtatic
php56w-mysql.x86_64 5.6.38-1.w7 @webtatic
php56w-opcache.x86_64 5.6.38-1.w7 @webtatic
php56w-pdo.x86_64 5.6.38-1.w7 @webtatic
php56w-xml.x86_64 5.6.38-1.w7 @webtatic
4.完全移除当前PHP安装包以免起冲突
yum remove php*
此处也可用 yum remove php56w*
默认的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
我们以php7.2为例:
正式安装php7.2:
1.查看yum源是否有php7.2安装包
yum list php72
2.安装php及相关插件
yum install php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysqlnd php72w-intl php72w-mbstring php72w-pear php72w-pdo php72w-fpm
其他版本php安装
如果想安装php7.0或者7.1版本,将上面的php72w替换为php70w或者php71w就可以了。
安装php扩展根据自己需求来
php72w-cli
php72w-common
php72w-devel
php72w-embedded
php72w-fpm
php72w-gd
php72w-mbstring
php72w-mysqlnd
php72w-opcache
php72w-pdo
php72w-xml
php72w
php72w-bcmath
php72w-dba
php72w-enchant
php72w-imap
php72w-interbase
php72w-intl
php72w-ldap
php72w-mcrypt
php72w-odbc
php72w-pdo_dblib
php72w-pear
php72w-pecl-apcu
php72w-pecl-imagick
php72w-pecl-xdebug
php72w-pgsql
php72w-phpdbg
php72w-process
php72w-pspell
php72w-recode
php72w-snmp
php72w-soap
php72w-tidy
php72w-xmlrpc
php72w-pecl-igbinary
php72w-intl
php72w-memcached
php72w-pecl-mongodb
推荐用 php72w-mysqlnd 替代 php72w-mysql
3.查看当前php版本
php -v