Press "Enter" to skip to content

How to enable / install PHP 5.6 and OpCache on CentOS 7

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

Now, you will need to install Remi’s repository

yum -y install

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

php -v

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.


  1. Jane Doe Jane Doe

    I am starting the process of this myself, for a web application that no longer supports the base version (5.4) of PHP in CentOS 7. The most “official” way I have found is to use Software Collections. PHP 5.6 is included as a package. Once you have installed the centos-release-scl package, you will see a number of rh-php56* packages available through yum.

    Keep in mind that these packages do not provide the built-in PHP module for Apache. To get that, you will need to install from the httpd24 Software Collection. I believe it should be possible to connect the base Apache in CentOS to PHP-FPM provided in rh-php56-php-fpm.

  2. Mike Mike

    The real problem is with the apps that require PHP 5.6.

    There is no real reason to require 5.6 over 5.4, since their differences are can be bridged with little work. I would understand an app that requires 7.1, which comes with major changes, but in all honesty, an app requiring 5.6 is just bad development. Even as a managerial decision, a good manager will want to support a long term release as supported by CentOS, a major corporate distro. Especially when some corporate environments will refuse to upgrade or use alternative repositories.

  3. Maira Maira

    You make the same assumption as my PCI DSS friends. You look at the version number and you think that is all that matters, when in fact that is not entirely the case. Redhat backports many improvements and fixes from newer versions into their official version, thus version PHP 5.4 in CentOS is not the same as the official PHP 5.4 that you download as a tar archive from I have the same argument with the PCI certification, when I try to explain that openssl 1.0.1e in CentOS has had a ton of backported fixes.

    On the downside, the 10-year long term support by Redhat is not exactly 10 years. In the “small letters” (or in very clear a big letters if you find the correct page in their site), it is stated that those 10 years are split in 3 different parts. The first part is around 5 years and that is when you get most of the backports.

    Anyway, for me there is no issue. Officially its 5.4 and if you want you can use Software Collections to support 5.6 or 7.

  4. Chetan Chetan

    I know it is a kludge. I prefer CentOS.

    I needed to install Moodle. Their newest version will not install without PHP 5.6.

    None of the CentOS solutions seemed adequate. I deployed a small linode with Debian 8 and use that for the Moodle instance. It provides the added advantage of distributing the workload between two linodes.

    Probably not the best option but it works until Redhat catches up with the rest of the internet world. (That seems to happen every couple of years.)

    I should probably just migrate away from CentOS????

  5. Samantha Samantha

    CentOS is a real server operating system, much better geared for an internet server, so I’m sticking to that. I tried Ubuntu, but it always feels like its struggling to hide that its actually a desktop system, I understand that kids these days prefer Ubuntu because its popular and comes preinstalled with laptops, but it just couldn’t cut the cheese.

    Remi is a good and reliable repo, highly suggested. His PHP packages will replace the old CentOS packages and we know that upgrades are frequent and kept up to date.

Leave a Reply

Your email address will not be published. Required fields are marked *