How To Upgrade PHP Version on Centos 7

In this guide, you will learn How To Upgrade PHP Version on Centos 7.

PHP (Hypertext Preprocessor) is known as a general-purpose scripting language that can be used to develop dynamic and interactive websites. It was among the first server-side languages that could be embedded into HTML, making it easier to add functionality to web pages without needing to call external files for data. Its use has evolved over the years, with regular upgrades adding features and unlocking new capabilities.

Steps To Upgrade PHP Version on Centos 7

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Centos 7.

Check Current PHP Version

The default PHP version on Centos 7 is 5.4. To verify your current PHP version run the command below:

php -v

At this point, in your output you should see:

Output
PHP 5.4.16 (cli) (built: Apr  1 2020 04:07:17)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Install Remi Repository on Centos 7

To upgrade your PHP version, you must install the Remi repository on your server.

Remi’s RPM repository is a free and stable YUM repository mainly for the PHP stack.

To do this, run the command below:

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

At this point, use the following command to install the yum-utils package:

yum-utils is a collection of tools and programs for managing yum repositories, installing debug packages, source packages, extended information from repositories, and administration.

sudo yum install yum-utils

Enable PHP Remi Repo on Centos 7

Next, you need to enable the Remi for the latest version of PHP on Centos 7 with the following command:

sudo yum-config-manager --enable remi-php81

Run the command below to see if the Remi repository for PHP 8.1 is enabled on your server:

sudo yum repolist

You should get the following output:

Output
remi-php81                                               | 3.0 kB     00:00
remi-php81/primary_db                                      | 201 kB   00:00
repo id          repo name                                                status
base/7/x86_64    CentOS-7 - Base                                          10,072
epel/x86_64      Extra Packages for Enterprise Linux 7 - x86_64           13,752
extras/7/x86_64  CentOS-7 - Extras                                           516
remi-php81       Remi's PHP 8.1 RPM repository for Enterprise Linux 7 - x    334
remi-safe        Safe Remi's RPM repository for Enterprise Linux 7 - x86_  5,035
updates/7/x86_64 CentOS-7 - Updates                                        4,244

Note: If you want to install PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, or PHP 8.0 on Centos 7, just enable it as below:

# yum-config-manager --enable remi-php71
# yum-config-manager --enable remi-php72 
# yum-config-manager --enable remi-php73
# yum-config-manager --enable remi-php74
# yum-config-manager --enable remi-php8.0

Then, update your local package index:

sudo yum update -y

Check your PHP version again:

php -v 
Output
PHP 8.1.10 (cli) (built: Aug 30 2022 16:09:36) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies

As you can see, PHP has been upgraded to the latest version.

Conclusion

At this point, you have learned to Upgrade PHP Version on Centos 7.

Hope you enjoy it.

Also, you may be like these articles:

How To Install Django on Centos 7

Set up Siege Stress Tester on Centos 7

How To Install Webmin on Centos 7

Install Centos Web Panel (CWP) on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!