How to Install PHP 7 on a CentOS Cloud Server?

19-01-2024 05:33:50

As CentOS by default installs PHP version 5, if we need to install the updated PHP 7 on CentOS, it is necessary to use third-party repositories. A commonly used third-party repository for PHP 7 is webtatic. The following demonstrates the method for installing PHP 7 on a CentOS cloud server.

Installing webtatic

For CentOS 7 system:

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

For CentOS 6 system:

yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Installing PHP 7

Installing PHP 7.2:

yum install mod_php72w php72w-fpm php72w-opcache

Upgrading from an older version to PHP 7.2:

yum install yum-plugin-replace
yum replace php-common --replace-with=php72w-common

Installing relevant extensions:

yum install php72w-common php72w-gd php72w-mbstring php72w-mysql

For more extensions, please refer to the official webtatic website:

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