Update to PHP 5.6 on CentOS 6 using remi repository

php_updateWith CentOS being a conservative distribution, security patches are still applied to CentOS 6, but no new versions are available. When running some websites – like Virtualmin – on CentOS 6, the old PHP version 5.3.3 can cause problems. Updating to a newer version of PHP will help avoid those problems.

The CentOS 6 repositories do not provide a PHP version higher than 5.3.3, so a third party repository has to be used. In the following article, the repositories from remi are used. The website for the remi repositories provides a wizard that will guide you through the process of installing the repositories and updating PHP. There are many different remi repositories for different purposes.

In this article the focus is not on installing multiple versions of PHP but updating the version to PHP 5.6 on CentOS 6.

When the Remi’s RPM repository – Configuration wizard is opened, 3 options need to be filled to get the step by step guide.
* Operating System: CentOS 6
* PHP version: 5.6.22 (active support until Dec 2016)
* Type of installation: Single version

The result will be a guide to install and enable the remi repository providing PHP in version 5.6.22 for CentOS 6.

The first step is to install the EPEL repository if that is not already installed. The EPEL repository is the Redhat “Extra Packages for Enterprise Linux (EPEL)” providing additional packages not in the default Redhat or CentOS repositories.

$ yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

The second step installs the remi repository configuration package. This package will contain multiple repositories, nearly all of them disabled by default.

$ yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm

The third step installs the “yum-utils” package. This package contains a lot of useful yum related utilities.

$ yum install yum-utils

The fourth step will enable the correct repository to update the already installed PHP version to 5.6. To do so, the just installed “yum-config-manager” (via yum-utils) is used to enable the “remi-php56” repository.

$ yum-config-manager --enable remi-php56

The final fifth step is a simple update of the system, which will show updated packages for every PHP package already installed on the system.

$ yum update
Loaded plugins: etckeeper, fastestmirror, priorities, security
Setting up Update Process
Loading mirror speeds from cached hostfile
 * base: ftp.hosteurope.de
 * epel: mirror.nl.leaseweb.net
 * extras: ftp.hosteurope.de
 * remi-php56: remi.mirrors.cu.be
 * remi-safe: remi.mirrors.cu.be
 * updates: ftp.hosteurope.de
warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56:
 Userid : Remi Collet <RPMS@FamilleCollet.com>
 Package: remi-release-6.6-2.el6.remi.noarch (@/remi-release-6)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Is this ok [y/N]: y

The output above shows the list of repositories used. The two new repositories remi-safe and remi-php56 are now providing the PHP version 5.6 for CentOS 6. The GPG key used to sign the packages are also installed during the first install / update.

After the update to PHP 5.6 I noticed that my website was not working anymore. The PHP files were provided as file downloads when i tried to open a PHP driven website. The reason is the PHP configuration found in the apache config directory.

Edit the configuration file “/etc/httpd/conf.d/php.conf” with your favourite editor. In this file the following section can be found.

# mod_php options
<IfModule  mod_php5.c>
    # Cause the PHP interpreter to handle files with a .php extension.
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php

The FilesMatch section needs to be commented out and replaced by the “AddHandler” directive like shown in the following example.

# mod_php options
<IfModule  mod_php5.c>
    # Cause the PHP interpreter to handle files with a .php extension.
    #<FilesMatch \.php$>
    #    SetHandler application/x-httpd-php
    AddHandler php5-script .php

After updating the PHP version, all websites served should be checked as the update to a higher version could cause different behaviour.

Read more of my posts on my blog at https://blog.tinned-software.net/.

This entry was posted in PHP, Web technologies and tagged , , . Bookmark the permalink.