How to Install Latest PHP 8.1 on AlmaLinux

With PHP 8.x version stream out, it is important for Linux users such as those under AlmaLinux to quickly adapt to this new version change due to the feature improvements associated with it.

PHP 8.x boasts of remarkable features and feature improvements such as Union Types, JIT (Just in Time) compiler support, the NullSafe Operator, Named Arguments, Attributes, Match Expression, Constructor Property Promotion, Throw Expression, and Inheritance with Private Methods.

AlmaLinux being a free, open-source, and community-supported Linux distribution makes it a perfect candidate for PHP 8.x installation. This open-source server-side scripting language has a lot of contributive footprint in generating dynamic web pages towards the creation of performant web applications.

Prerequisites

Ensure that you are a root/sudoer user of the AlmaLinux operating system you are using.

We can now begin the article walk-through on installing and configuring PHP 8.x on AlmaLinux operating system.

Installing PHP 8 on AlmaLinux

Your AlmaLinux operating system needs to be up-to-date for the best performance.

$ sudo dnf update && sudo dnf upgrade -y

There is no direct way of installing PHP 8.x on AlmaLinux without going through the EPEL and Remi repositories. This repo makes it possible to not only install PHP’s latest version release but also keep track of future version releases.

You, therefore, do not have to worry about the PHP version you need to use on your web application projects.

$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

In order for AlmaLinux to recognize the addition of repositories, you need to run a system update for the second time.

$ sudo dnf update && sudo dnf upgrade -y 

We are now ready to use the Remi repo for PHP installation. The first step is to list all the available PHP versions this repository has to offer AlmaLinux. We will use the list module command.

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

As you can see, the above command lists PHP 7.x module. In order to get PHP 8.x modules, we first need to reset the default PHP 7.x module.

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

After resetting PHP from its default module, we should now be able to see the PHP modules Remi repo has to offer by re-running the module list command.

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

As you can see, the Remi repository offers PHP versions from 7.2 to 8.1.

Since PHP 8.1 is the latest version release under Remi repo, we first need to enable it before we can proceed and install PHP 8.1, or else PHP 7.4 from AppStream will be installed.

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

We can now proceed and install PHP 8.1 on AlmaLinux.

$ sudo dnf install php -y
Install PHP in AlmaLinux
Install PHP in AlmaLinux

Check on PHP installed version.

$ php --version
Check PHP in AlmaLinux
Check PHP in AlmaLinux

To install additional PHP extensions, adhere to the syntax:

$ sudo dnf install php-extension-name  

For instance, we can install the php-fpm extension:

$ sudo dnf install php-fpm

Your AlmaLinux system is now installed and configured with the latest version of PHP (8.1).

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.