How To Upgrade PHP 5.6 to 7.2 in CentOS 7 Linux

In this post I’ll show you how to upgrade PHP 5.6 to 7.2 in CentOS 7 Linux.

How To Upgrade PHP 5.6 to 7.2

For PHP 5.6 I’ve been using the Webtatic repository. This is a third party repository that allows me to install newer versions of PHP in CentOS 7.

Webtatic repository Installation
To set up the repository, install the webtatic-release RPM:

CentOS/RHEL 7.x:

yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

CentOS/RHEL 6.x:

yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Preparing for PHP Update
Before beginning we can see that we’re currently running PHP version 5.6.40.

[root@demo ~]# php -v
PHP 5.6.40 (cli) (built: Jan 12 2019 13:11:15) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

Now let’s get an idea of the packages that we need to upgrade. I’ll run yum list installed then grep for webtatic so that we can see all packages installed from this repository.

[root@demo ~]# yum list installed | grep -i webtatic
php56w.x86_64                        5.6.40-1.w7                       @webtatic
php56w-cli.x86_64                    5.6.40-1.w7                       @webtatic
php56w-common.x86_64                 5.6.40-1.w7                       @webtatic
php56w-gd.x86_64                     5.6.40-1.w7                       @webtatic
php56w-intl.x86_64                   5.6.40-1.w7                       @webtatic
php56w-mbstring.x86_64               5.6.40-1.w7                       @webtatic
php56w-mcrypt.x86_64                 5.6.40-1.w7                       @webtatic
php56w-mysql.x86_64                  5.6.40-1.w7                       @webtatic
php56w-pdo.x86_64                    5.6.40-1.w7                       @webtatic
php56w-pear.noarch                   1:1.10.4-1.w7                     @webtatic
php56w-process.x86_64                5.6.40-1.w7                       @webtatic
php56w-xml.x86_64                    5.6.40-1.w7                       @webtatic
webtatic-release.noarch              7-3                               installed

Note down all of these PHP packages, we’ll need them later.

Remove Old PHP Packages
While you can use something like

yum replace

for this, I just used

yum remove

to remove all of the previously listed PHP packages. Remember to keep note of these, as we’ll need that in the next step.

yum remove php*

Install PHP 7.2

Now with the list of PHP packages that we previously removed, we simply copy them. The ‘w’ on the end of the package means it’s Webtatic.

yum install php72w php72w-cli php72w-common php72w-gd php72w-intl php72w-mbstring php72w-mcrypt php72w-mysql php72w-pdo php72w-pear php72w-process php72w-xml

We can now see that we’re running PHP 7.2.

PHP 7.2.14 (cli) (built: Jan 12 2019 12:47:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

As shown we have shown you how to upgrade PHP 5.6 to 7.2 successfully.

Leave a Reply

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