How To Install PHP 8.1 on Centos 7

In this article, we want to teach you How To Install PHP 8.1 on Centos 7.

PHP is a server-side scripting language. that is used to develop Static websites or Dynamic websites or Web applications. It stands for Hypertext Pre-processor, which earlier stood for Personal Home Pages.

PHP scripts can only be interpreted on a server that has PHP installed. The client computers accessing the PHP scripts require a web browser only. A PHP file contains PHP tags and ends with the extension “.php”.

In this guide, you learn to install the latest release of PHP on Centos 7.

Steps To Install PHP 8.1 on Centos 7

Before you start to install PHP 8.1, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Centos 7.

Now you can follow the steps below to complete this guide.

Installation of PHP 8 on Centos 7

First, you need to update your local package index with the command below:

sudo yum update -y

Then, you need to install the Epel release on Centos 7 with the command below:

sudo yum install epel-release

Install Remi Repository on Centos 7

PHP 8.1 is not featured in Centos’s AppStream. So you can install PHP from the (Remi) repository that deploys the latest PHP 8.1 builds. To do this, run the following command:

sudo yum -y install yum-utils https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Update your local package index again:

sudo yum update -y

Now you need to remove the PHP and PHP-FPM previous versions if you have them installed on your server. To do this run the following command:

sudo yum remove php php-fpm -y

Then remove the rest of the package extensions with the command below:

sudo yum remove php* -y

Now disable the Remi repository for PHP with the following command:

sudo yum-config-manager --disable 'remi-php*'

Enable PHP Remi Repository on Centos 7

Next, you need to enable the Remi for PHP 8.1 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
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,749
extras/7/x86_64 CentOS-7 - Extras 509
remi-php81 Remi's PHP 8.1 RPM repository for Enterprise Linux 7 - x 292
remi-safe Safe Remi's RPM repository for Enterprise Linux 7 - x86_ 4,703
updates/7/x86_64 CentOS-7 - Updates 3,572
repolist: 32,897

Install PHP 8.1 on Centos 7

At this point, you can install PHP 8.1 on Centos 7 with the command below:

sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json,opcache,redis,memcache}

To install all the PHP extensions, you can use the following command:

sudo yum install php-xxx

Verify your PHP installation on Centos 7 by checking its version:

php --version
Output
PHP 8.1.3 (cli) (built: Feb 16 2022 01:00:24) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.3, Copyright (c) Zend Technologies
with Zend OPcache v8.1.3, Copyright (c), by Zend Technologies

For more information, you can visit the PHP Documentation Page.

Conclusion

At this point, you learn to Install PHP 8.1 on Centos 7.

Hope you enjoy it.

May you will be interested in these articles:

How To Install Wekan Server on Centos 7.

How To Set up Ntopng on Centos 7.

Install and Use MonoDevelop on Centos 7.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!