How to Install PHP 7.4 and 8.1 in AlmaLinux 9
On AlmaLinux 9, PHP 8.1 packages are not available in the default OS AppStream repositories. By default, the version of PHP available on our AlmaLinux to install is PHP 8.0, so to get the newer versions such as PHP 8.1, we need to add/enable third-party repositories such as Remi.
To install PHP 8.1, we’ll need to add/enable the Remi RPM repositories which contain the PHP 8.1 packages that we need.
Pre-requisites :
-
A system with AlmaLinux 9 installed and running.
- root access to the system.
First, let’s start by ensuring your system is up-to-date.
dnf update
Installing the EPEL and Remi Repository
For this, we use the PHP 7.4 and 8.1 packaged by Remi,
First, let us install the EPEL repository,
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
Next, install the Remi repository with the following command,
dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Output:
[root@server ~]# dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Last metadata expiration check: 2:43:17 ago on Thu Jun 2 15:33:16 2022.
remi-release-9.rpm 169 kB/s | 25 kB 00:00
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
remi-release noarch 9.0-6.el9.remi @commandline 25 k
Installing dependencies:
epel-release noarch 9-2.el9 extras 17 k
Transaction Summary
================================================================================
Install 2 Packages
List the available PHP module stream
To check/list the available PHP versions, use the following command,
dnf module list php
Output:
[root@server ~]# dnf module list php
Remi's Modular repository for Enterprise Linux 4.7 kB/s | 833 B 00:00
Remi's Modular repository for Enterprise Linux 3.0 MB/s | 3.1 kB 00:00
Importing GPG key 0x478F8947:
Userid : "Remi's RPM repository (https://rpms.remirepo.net/) <remi@remirepo.net>"
Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
Is this ok [y/N]: y
Remi's Modular repository for Enterprise Linux 2.6 MB/s | 545 kB 00:00
Safe Remi's RPM repository for Enterprise Linux 6.9 kB/s | 833 B 00:00
Safe Remi's RPM repository for Enterprise Linux 3.0 MB/s | 3.1 kB 00:00
Importing GPG key 0x478F8947:
Userid : "Remi's RPM repository (https://rpms.remirepo.net/) <remi@remirepo.net>"
Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
Is this ok [y/N]: y
Safe Remi's RPM repository for Enterprise Linux 3.1 MB/s | 700 kB 00:00
Remi's Modular repository for Enterprise Linux 9 - x86_64
Name Stream Profiles Summary
php remi-7.4 common [d], devel, minimal PHP scripting language
php remi-8.0 common [d], devel, minimal PHP scripting language
php remi-8.1 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@server ~]#
Installing PHP 7.4
Now, let's install PHP 7.4 via the remi repository,
dnf module install php:remi-7.4
Output:
[root@server ~]# dnf module install php:remi-7.4
Last metadata expiration check: 0:00:12 ago on Thu Jun 2 18:18:29 2022.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing group/module packages:
php-cli x86_64 7.4.29-1.el9.remi remi-modular 4.5 M
php-common x86_64 7.4.29-1.el9.remi remi-modular 787 k
php-fpm x86_64 7.4.29-1.el9.remi remi-modular 1.6 M
php-mbstring x86_64 7.4.29-1.el9.remi remi-modular 519 k
php-xml x86_64 7.4.29-1.el9.remi remi-modular 172 k
Installing dependencies:
libxslt x86_64 1.1.34-9.el9 appstream 240 k
oniguruma5php x86_64 6.9.8-1.el9.remi remi-safe 219 k
php-json x86_64 7.4.29-1.el9.remi remi-modular 38 k
You can update your system and install packages at any time by running the following command,
dnf update
Check Installed PHP Version
Now that we have installed PHP 7.4 via the remi repository, we can verify the version installed by running the php -v
command,
php -v
Output:
[root@server ~]# php -v
PHP 7.4.29 (cli) (built: Apr 12 2022 10:55:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Installing PHP 8.1
Now, let's install PHP 8.1 via the remi repository,
dnf module install php:remi-8.1
Output:
[root@server ~]# dnf module install php:remi-8.1
Last metadata expiration check: 0:15:28 ago on Thu Jun 2 18:18:29 2022.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Upgrading:
php-cli x86_64 8.1.6-1.el9.remi remi-modular 5.2 M
php-common x86_64 8.1.6-1.el9.remi remi-modular 827 k
replacing php-json.x86_64 7.4.29-1.el9.remi
php-fpm x86_64 8.1.6-1.el9.remi remi-modular 1.8 M
php-mbstring x86_64 8.1.6-1.el9.remi remi-modular 517 k
php-xml x86_64 8.1.6-1.el9.remi remi-modular 204 k
Installing module profiles:
php/common
Enabling module streams:
php remi-8.1
Transaction Summary
================================================================================
Upgrade 5 Packages
You can update your system and install packages at any time by running the following command,
dnf update
Check Installed PHP Version
Now that we have installed PHP 8.1 via the remi repository, we can verify the version installed by running the php -v
command,
php -v
Output:
[root@server ~]# php -v
PHP 8.1.6 (cli) (built: May 11 2022 01:14:18) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
DONE!
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS