一、安装源
//首先切换到root用户
yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
二、清除历史版本
yum -y remove php*
三、安装PHP相关包
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
注意:若使用了redis,则需要添加redis扩展。
yum install php72w-pecl-redis.x86_64
四、启动服务
systemctl enable php-fpm.service
systemctl start php-fpm.service
五、测试
php -v
若看到php版本号,无报错信息,则说明安装正确。
PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies