Home PHP How to Install Latest PHP 8 on Rocky Linux

How to Install Latest PHP 8 on Rocky Linux

Developers behind the creation of the Rocky Linux operating system insisted on it being 100% bug-for-bug compatible with RHEL.

This bug compatibility trait enables Rocky Linux to replicate out-of-favor features from its previous OS version releases to the current one. This backtracking feature is important to web application developers especially the ones under the premise of the PHP programming language.

These developers and users are able to implement new/improved PHP 8 features like named arguments, constructor property promotion, match expression, a saner string to number comparisons, attributes, union types, nullsafe operator, and consistent type errors for internal functions.

This article will walk us through the installation and configuration of PHP 8 and its extensions on the Rocky Linux operating system.

Prerequisites

Ensure you are a root/sudoer user of the Rocky Linux operating system you are using.

Installing PHP 8 on Rocky Linux

Make sure the Rocky Linux you are using is up-to-date by executing the following command:

$ sudo dnf update && sudo dnf upgrade -y

Now that you have updated Rocky Linux and it is at its best performance state, you need to add the EPEL and Remi repositories. These repos are the bridge to installing PHP 8 current and future version releases.

Accomplishing these repos addition steps gets you that specific PHP version you need for your web application projects.

$ sudo dnf install epel-release -y
$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

If you have an older version of PHP on your Rocky Linux system and no longer need it or feel like it does not match your current web projects/applications needs, uninstall it with the command:

$ sudo dnf remove php* -y

Next, you need to do a system update to ensure that Rocky Linux recognizes the addition of the EPEL and Remi repository.

$ sudo dnf update && sudo dnf upgrade -y

Finally, check for the availability of installable PHP versions on Rocky Linux. You should be able to see a list of PHP versions ranging from 7.2 to 8.x.

$ sudo dnf module list php
List PHP Module
List PHP Module

Under Remi’s Modular repository, we can note the available PHP versions ranging from version number 7.2 to 8.1. If you are using the Remi repository for the first time to install PHP, you first need to reset PHP from its default module.

$ sudo dnf module reset php
Reset PHP Module in RockyLinux
Reset PHP Module in RockyLinux

Afterward, you should be able to select/choose the PHP module you wish to use on your Rocky Linux system. In this case, it will be between PHP 8.0 and PHP 8.1.

For instance, to enable PHP:Remi-8.1 module, we will execute the command:

$ sudo dnf module enable php:remi-8.1  
Enable PHP Module
Enable PHP Module

After enabling, you can able to install PHP 8.1 on Rocky Linux.

$ sudo dnf install php -y
Install PHP 8 in RockyLinux
Install PHP 8 in RockyLinux

The installation of PHP 8.1 will also be accompanied by the installation of popular PHP extensions as noted on the above screen capture.

To confirm the installed PHP version:

$ php --version
Check PHP in RockyLinux
Check PHP in RockyLinux

To install other PHP extensions, use the syntax:

$ sudo dnf install php-extension_name  

For instance, to install php-mysqlnd:

$ sudo dnf install php-mysqlnd

You can now explore what PHP 8 has to offer your Rocky Linux web projects/applications.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.