Update 26-Feb-2020: See the updated version of this guide here: Upgrade to PHP 7 on CentOS 7 (or CentOS 6)
You may find that you need to upgrade PHP on your CentOS install in order to meet dependencies for an application. For example, a WordPress plugin:
Gmail SMTP plugin requires PHP 5.6 or higher. Please contact your web host to update your PHP version.
CentOS by nature maintains the same package version throughout the life cycle of its release, so for CentOS 7 you end up with PHP version 5.4 (e.g., 5.4.17).
The good news is that you can upgrade PHP using the IUS Community project repositories without breaking your CentOS install.
Here are the steps, which need to be run with sudo permissions:
yum --enablerepo=extras install epel-release
For CentOS 7: yum install https://centos7.iuscommunity.org/ius-release.rpm For CentOS 6: yum install https://centos6.iuscommunity.org/ius-release.rpm
yum install yum-plugin-replace
yum replace --replace-with php56u php
With the last step you may receive the following warning:
WARNING: Unable to resolve all providers ... This may be normal depending on the package. Continue? [y/N]
For this procedure the warning is typical, so hit Yes
You will then be presented with a transaction summary as follows:
Transaction Summary ======================================== Install x Package(s) .... Remove x Package(s) ... Is this ok [y/N]:
Verify that all of the packages being removed are being replaced with equivalent packages of the newer version. Then hit Yes.
Once complete, restart all services that use PHP or reboot the server. Typically this is Apache, so to restart it issue the following command:
sudo apachectl restart