CentOS is one of the most trusted operating systems for hosting web services and apps. One of the main reasons behind this being popular is the fact that it prefers stability over the features. The OS is way more stable as compared to the other choices we have while deploying the servers. Favouring stability over features is one of the reasons why CentOS lags a lot behind in terms of software version it provides to the users.
Though CentOS officially lags behind the other counterparts in providing the latest releases of various apps and software, there are a number of the third party applications which allow CentOS users to run the latest versions of available apps. In this tutorial, I am going to guide you on how to enable or install PHP 5.6 on CentOS 7. Along with PHP, this guide will also talk about installing Opcache, the bundled cache system within PHP. If you are looking to install only Opcache, you will need to keep in mind that it needs PHP 5.5 or higher. Currently, CentOS officially provides PHP 5.4 as their latest available version and that means, if you want to enable Opcache on your server, you will need to upgrade PHP first.
If you have any queries going through the article, feel free to reach out to me through the comment section or email and I will try my best to solve that for you.
For my needs, I use a third-party repository called Remi’s RPM repository. This has a lot of available versions of needed scripts and they can be installed on any CentOS powered VPS or droplet. However, before you can install any of these scripts on the server, you will first need to install Remi’s repository. Let’s get started
The below code will need to be executed in order to achieve the task of upgrading PHP and installing Opcache. If your motive is to only upgrade PHP on the server, feel free to omit the steps I have included for installing that and continue with the steps meant only for upgrading PHP (As mentioned alongside each command).
The first step includes installing EPEL release because Remi’s repository works on that.
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Now, you will need to install Remi’s repository
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Install yum-utils (contains yum-config-manager which we use next):
yum -y install yum-utils
The below line of code will enable the PHP 5.6 repository.
yum-config-manager --enable remi-php56
And proceed to update PHP to 5.6
yum -y update
Check the PHP version on your server to make sure if it has been updated
Now, restart the webserver to save these changes and check that all sites are still functional.
If you are looking to install opcache as well, this can be done by using a simple command,
yum -y install php-opcache
One more webserver restart will be necessary to apply the change.