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
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
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
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
We can now proceed and install PHP 8.1 on AlmaLinux.
$ sudo dnf install php -y
Check on PHP installed version.
$ php --version
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).
When I run the command `
sudo install php -y
`, I get the following error message:“All matches were filtered out by exclude filtering for argument: php Error: Unable to find a match: PHP”
@Adam,
To fix this issue, you can use the correct package manager command to install PHP. The correct command is: