Upgrade PHP 5.3 to PHP 7.0 using yum on CentOS/RHEL/Fedora

Updated on November 5, 2017

My web server was running PHP version 5.3 for a long time and now I would like to en-cash the advantages of PHP 7.0. So I decided to upgrade PHP 5.3 to PHP 7.0. As this is a production web server, I don’t want to disturb the existing setup and also, I don’t want to have multiple versions on PHP installed. So it should be a pure upgrade of PHP.

MySQL Original API deprecated in PHP 7.0 - Use MYSQLi

Make sure your MySQL DB connections are adhering to the standards supported in PHP 7.0. For e.g., The MySQL original API has been deprecated in PHP 7. So mysql_connect() should be replaced with mysqli_connect() and so on.

Here is a quick guide to help you upgrade default PHP provided on Fedora, CentOS, RHEL to latest version 7.0 (at the time of writing this article).

Don't Panic if upgrade fails, it may be due to incompatible extensions.

The upgrade may fail due to already installed extensions that may not be compatible with PHP 7. Check for the PHP extensions and versions compatible with PHP 7.0 from here. If the extensions are not mandatory, you can either remove them before upgrade or else, be patient.

Step 1: How to configure Remi repository in CentOS/Fedora/RHEL

Additional Repositories with Remi

On Fedora, standard repositories are enough, whereas on RHEL/CentOS, the EPEL repository must be configured and on RHEL the optional channel must be enabled.

RHEL 6.7

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
rhn-channel --add --channel=rhel-$(uname -i)-server-optional-6

RHEL 7.2

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
subscription-manager repos --enable=rhel-7-server-optional-rpms

Centos 6.7

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm

CentOS 7.2

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm

Fedora 23

wget http://rpms.remirepo.net/fedora/remi-release-23.rpm
dnf install remi-release-23.rpm

Step 2: Activate Remi repository

By default, Remi-safe repository would be enabled and remi-php70 would be disabled. If you want to enable it permanently, open the file /etc/yum.repos.d/remi.repo and change the value of enabled from 0 to 1 under remi-php70 section.

vim /etc/yum.repos.d/remi.repo

or by using the below yum command:

RHEL et CentOS

yum-config-manager --enable remi-php70
Pre-requisites

If you don’t have yum-utils installed, then you will get an error “yum-config-manager command not found”. Click here to fix this error.

Fedora

dnf config-manager --set-enabled remi-php70

Step 3: Upgrade PHP 5.3 to PHP 7.0

yum update

That’s all 🙂

Step 4: Verify the PHP version

You may verify PHP version using the below command:

php --version
PHP 7.0.24 (cli) (built: Sep 26 2017 18:04:56) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

Was this article helpful?

Related Articles

Comments Leave a Comment

Leave a Comment