How To Upgrade PHP 7.0 to 7.2 in CentOS 7 Linux

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

How To Upgrade PHP 7.0 to 7.2

For PHP 7.0 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

CentOS/RHEL 6.x:

yum install epel-release
rpm -Uvh

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

[root@demo ~]# php -v
HP 7.0.33 (cli) (built: Dec  6 2018 22:30:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 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
php70w.x86_64                        7.0.33-1.w7                       @webtatic
php70w-cli.x86_64                    7.0.33-1.w7                       @webtatic
php70w-common.x86_64                 7.0.33-1.w7                       @webtatic
php70w-gd.x86_64                     7.0.33-1.w7                       @webtatic
php70w-intl.x86_64                   7.0.33-1.w7                       @webtatic
php70w-mbstring.x86_64               7.0.33-1.w7                       @webtatic
php70w-mcrypt.x86_64                 7.0.33-1.w7                       @webtatic
php70w-mysql.x86_64                  7.0.33-1.w7                       @webtatic
php70w-pdo.x86_64                    7.0.33-1.w7                       @webtatic
php70w-pear.noarch                   1:1.10.4-1.w7                     @webtatic
php70w-process.x86_64                7.0.33-1.w7                       @webtatic
php70w-xml.x86_64                    7.0.33-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.17 (cli) (built: May 13 2019 18:03:04) ( 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 7.0 to 7.2 successfully.

Leave a Reply

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