How to Install PHP 7 x in AlmaLinux 8

Installing the EPEL and Remi Repository

For this we use the PHP 7.4 packaged by Remi, a third-party repository which offers multiple versions of PHP 7.x and 8.x

First, lets install the EPEL repository,

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Next, install the Remi repository with the following command,

yum install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Output:

[root@server ~]# yum install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Extra Packages for Enterprise Linux Modular 8 - 558 kB/s | 536 kB     00:00
Extra Packages for Enterprise Linux 8 - x86_64  6.5 MB/s | 8.8 MB     00:01
Last metadata expiration check: 0:00:01 ago on Wed 10 Feb 2021 02:27:25 PM EST.
remi-release-8.rpm                               42 kB/s |  25 kB     00:00
Dependencies resolved.
================================================================================
 Package            Architecture Version               Repository          Size
================================================================================
Installing:
 remi-release       noarch       8.3-1.el8.remi        @commandline        25 k

List the available PHP module stream

To check/list the available PHP versions, use the following command,

yum module list php

Output:

[root@server ~]# yum module list php
Remi's Modular repository for Enterprise Linux  447 kB/s | 730 kB     00:01
Safe Remi's RPM repository for Enterprise Linux 934 kB/s | 1.6 MB     00:01
Last metadata expiration check: 0:00:01 ago on Wed 10 Feb 2021 02:28:15 PM EST.
AlmaLinux 8.3 - AppStream
Name     Stream         Profiles                       Summary
php      7.2 [d][e]     common [d], devel, minimal     PHP scripting language
php      7.3            common [d], devel, minimal     PHP scripting language
php      7.4            common [d], devel, minimal     PHP scripting language

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name     Stream         Profiles                       Summary
php      remi-7.2       common [d], devel, minimal     PHP scripting language
php      remi-7.3       common [d], devel, minimal     PHP scripting language
php      remi-7.4       common [d], devel, minimal     PHP scripting language
php      remi-8.0       common [d], devel, minimal     PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Installing PHP 7.4

First, lets disable the old version before enabling the new one,

dnf module reset php

Output:

[root@server ~]# dnf module reset php
Last metadata expiration check: 0:16:54 ago on Wed 10 Feb 2021 02:31:22 PM EST.
Dependencies resolved.
=====================================================================================================
 Package                Architecture          Version                   Repository              Size
=====================================================================================================
Resetting modules:
 php

Transaction Summary
=====================================================================================================

Is this ok [y/N]: y
Complete!

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:17:27 ago on Wed 10 Feb 2021 02:31:22 PM EST.
Dependencies resolved.
=====================================================================================================
 Package                 Architecture     Version                       Repository              Size
=====================================================================================================
Upgrading:
 php                     x86_64           7.4.15-1.el8.remi             remi-modular           3.0 M
 php-cli                 x86_64           7.4.15-1.el8.remi             remi-modular           4.6 M
 php-common              x86_64           7.4.15-1.el8.remi             remi-modular           1.2 M
 php-fpm                 x86_64           7.4.15-1.el8.remi             remi-modular           1.6 M
 php-gd                  x86_64           7.4.15-1.el8.remi             remi-modular            93 k
 php-json                x86_64           7.4.15-1.el8.remi             remi-modular            76 k

You can update your system and installed 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.15 (cli) (built: Feb  2 2021 14:19:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by 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