The latest version of PHP is 7.4.8. But still, some are using previous versions of 5.x. I strongly recommend you upgrade to the latest version. If you want to upgrade to 5.6 only then this article is for you.
Let’s see how to upgrade the existing PHP 5.4 to PHP 5.6 version in a simple way.
First, check your existing PHP version by using ‘-v’ option
# php -v
Output should be like this:
PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
You need to install REMI and EPEL repositories to get PHP 5.6 packages
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
Now enable remi repositories
vim /etc/yum.repos.d/remi.repo
[remi]
name=Remi's RPM repository for Enterprise Linux 7 - $basearch baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/ mirrorlist=https://rpms.remirepo.net/enterprise/7/remi/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/remi/mirror <span class="has-inline-color has-vivid-red-color">enabled=1</span> gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php56]
name=Remi's PHP 5.6 RPM repository for Enterprise Linux 7 - $basearch baseurl=http://rpms.remirepo.net/enterprise/7/php56/$basearch/ mirrorlist=https://rpms.remirepo.net/enterprise/7/php56/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/php56/mirror NOTICE: common dependencies are in "remi-safe" <span class="has-inline-color has-vivid-red-color">enabled=1</span> gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Upgrade PHP using yum upgrade command.
# yum upgrade php* -y
Now check PHP version, it should show new version of the package.
# php -v
PHP 5.6.40 (cli) (built: Sep 29 2020 11:13:13)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
That’s it! We have successfully upgraded PHP.