Welcome to this guide on how to install PHP 8.1 on AlmaLinux 8|Oracle Linux 8. PHP is an open-source scripting language created by Rasmus Lerdorf, a Danish-Canadian programmer in 1994, with an aim of creating dynamic and interactive web pages. PHP servers as an alternative to Microsoft’s ASP. It is used to power the most powerful content management systems such as WordPress, Drupal, and Joomla.
The latest release, PHP 8.1 is an update of its previous release PHP 8.0. This new release version has a lot of amazing features that include:
- Readonly properties – Class properties can be marked as readonly hence can only be written once
- Enums are available in PHP 8.1
- Never Return Type – A new return type hint called never is added in PHP 8.1
- Fibers – this is a low level mechanism to manage parallelism
- Performance improvements – the inheritance cache feature that allows links between classes to be cached.
- First-class callable syntax
- AVIF Image Format support – The PHP 8.1’s image processing and GD extension adds support for AVIF images.
- Support for DNS-over-HTTPS (DoH)
- File Uploads with CURLStringFile – In PHP 8.1, PHP Curl extension now supports HTTP(S) requests with file uploads
- Pure intersection types
- Explicit octal integer literal notation
- Define final Class Constants
Let’s dive into the nub of this matter.
Step 1 – Add PHP 8.1 Remi Repository on AlmaLinux 8|Oracle Linux 8
PHP is found in the default AlmaLinux 8|Oracle Linux 8 repositories but the available versions here are far away from the latest release versions. The available releases of PHP can be viewed using the DNF command below.
$ sudo dnf module list php
determining the fastest mirror (10 hosts).. done.-- B/s | 0 B --:-- ETA
AlmaLinux 8 - BaseOS 6.6 MB/s | 3.8 MB 00:00
determining the fastest mirror (2 hosts).. done.--- B/s | 0 B --:-- ETA
AlmaLinux 8 - AppStream 7.2 MB/s | 8.2 MB 00:01
AlmaLinux 8 - Extras 25 kB/s | 12 kB 00:00
AlmaLinux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] 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
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
So, for us to be able to install this latest version, PHP 8.1, we need to add the Remi repository.
First, install the EPEL repo on AlmaLinux 8|Oracle Linux 8.
sudo dnf install epel-release
With the EPEL repository installed, we will proceed and enable the Remi repository as below.
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Dependency tree:
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
remi-release noarch 8.4-1.el8.remi @commandline 26 k
yum-utils noarch 4.0.21-3.el8 baseos 71 k
Upgrading:
dnf-plugins-core noarch 4.0.21-3.el8 baseos 69 k
python3-dnf-plugins-core noarch 4.0.21-3.el8 baseos 233 k
Transaction Summary
================================================================================
Install 2 Packages
Upgrade 2 Packages
Total size: 399 k
Total download size: 374 k
Is this ok [y/N]: y
Update your DNF package repository.
sudo dnf update
Accept the GPG key importation for the Remi repo.
Importing GPG key 0x5F11735A:
Userid : "Remi's RPM repository <[email protected]>"
Fingerprint: 6B38 FEA7 231F 87F5 2B9C A9D8 5550 9759 5F11 735A
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
Is this ok [y/N]: y
......
Safe Remi's RPM repository for Enterprise Linux 3.0 MB/s | 3.1 kB 00:00
Importing GPG key 0x5F11735A:
Userid : "Remi's RPM repository <[email protected]>"
Fingerprint: 6B38 FEA7 231F 87F5 2B9C A9D8 5550 9759 5F11 735A
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
Is this ok [y/N]: y
Step 2 – Enable PHP 8.1 Repository on AlmaLinux 8|Oracle Linux 8
From the previous output, we have seen that PHP 7.2 is the default version for PHP on Rhel based systems.
So after adding the Remi repository, we will list the available PHP options as below.
$ sudo dnf module list php
ast metadata expiration check: 0:16:07 ago on Tue 23 Nov 2021 02:21:16 AM EST.
AlmaLinux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] 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
php remi-8.1 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
The [d] tag next to PHP 7.2 indicates the default PHP version enabled on our system. We will first need to reset this before we enable the latest version PHP 8.1 provided by the Remi repository.
sudo dnf module list reset php
Now enable PHP 8.1 as below.
sudo dnf module enable php:remi-8.1
Sample Output:
Dependencies resolved.
==============================================================================
Package Architecture Version Repository Size
==============================================================================
Enabling module streams:
php remi-8.1
Transaction Summary
==============================================================================
Is this ok [y/N]: y
Step 3 – Install PHP 8.1 on AlmaLinux 8|Oracle Linux 8
Now after all the above configurations, we are now set to do the installation. Install the default enabled version PHP 8.1 using the command.
sudo dnf install php
Dependency tree:
Dependencies resolved.
==============================================================================
Package Arch Version Repository Size
==============================================================================
Installing:
php x86_64 8.1.0~RC6-1.el8.remi remi-modular 1.8 M
Installing dependencies:
almalinux-logos-httpd noarch 84.5-1.el8 appstream 29 k
apr x86_64 1.6.3-12.el8 appstream 128 k
apr-util x86_64 1.6.1-6.el8 appstream 105 k
httpd x86_64 2.4.37-43.module_el8.5.0+2597+c4b14997.alma
appstream 1.4 M
httpd-filesystem noarch 2.4.37-43.module_el8.5.0+2597+c4b14997.alma
appstream 39 k
httpd-tools x86_64 2.4.37-43.module_el8.5.0+2597+c4b14997.alma
appstream 106 k
libsodium x86_64 1.0.18-2.el8 epel 162 k
mod_http2 x86_64 1.15.7-3.module_el8.5.0+2576+c8e0c271
appstream 153 k
oniguruma5php x86_64 6.9.7.1-1.el8.remi remi-safe 210 k
php-common x86_64 8.1.0~RC6-1.el8.remi remi-modular 1.2 M
Installing weak dependencies:
apr-util-bdb x86_64 1.6.1-6.el8 appstream 24 k
apr-util-openssl x86_64 1.6.1-6.el8 appstream 27 k
nginx-filesystem noarch 1:1.14.1-9.module_el8.3.0+2165+af250afe.alma
appstream 23 k
php-cli x86_64 8.1.0~RC6-1.el8.remi remi-modular 5.3 M
php-fpm x86_64 8.1.0~RC6-1.el8.remi remi-modular 1.8 M
php-mbstring x86_64 8.1.0~RC6-1.el8.remi remi-modular 519 k
php-opcache x86_64 8.1.0~RC6-1.el8.remi remi-modular 609 k
php-pdo x86_64 8.1.0~RC6-1.el8.remi remi-modular 160 k
php-sodium x86_64 8.1.0~RC6-1.el8.remi remi-modular 100 k
php-xml x86_64 8.1.0~RC6-1.el8.remi remi-modular 249 k
Enabling module streams:
httpd 2.4
nginx 1.14
Transaction Summary
==============================================================================
Install 21 Packages
Total download size: 14 M
Installed size: 57 M
Is this ok [y/N]: y
Verify the installed PHP version on our system.
$ php --version
PHP 8.1.0 (cli) (built: Nov 23 2021 18:56:11) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
Step 4 – Install PHP 8.1 Extensions on AlmaLinux 8|Oracle Linux 8
PHP extensions are useful in that they minimize the tedious task of having to do the same code over and over for PHP applications from scratch.
These PHP 8.1 extensions can be installed using the command:
sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml
On a successful installation, you can check all the available PHP extensions.
$ php --modules
[PHP Modules]
apcu
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
imagick
imap
intl
json
libxml
mbstring
memcached
msgpack
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
redis
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
Step 5 – Run Multiple versions of PHP on AlmaLinux 8|Oracle Linux 8
It is possible to have multiple versions of PHP running on your system. Assuming you already have the default PHP version 7.2 installed, you can still install PHP 8.1 without necessarily having to set it as a default version before installation. This can be achieved through software collection a feature available in the Remi-safe repository.
In case you already have another PHP version installed, you can install PHP 8.1 using the command:
sudo dnf install php81
Dependency tree:
Dependencies resolved.
============================================================================
Package Arch Version Repository Size
============================================================================
Installing:
php81 x86_64 8.1-2.el8.remi remi-safe 7.4 k
Installing dependencies:
environment-modules x86_64 4.5.2-1.el8 baseos 421 k
php81-php-cli x86_64 8.1.0~rc6-1.el8.remi remi-safe 3.6 M
php81-php-common x86_64 8.1.0~rc6-1.el8.remi remi-safe 723 k
php81-runtime x86_64 8.1-2.el8.remi remi-safe 1.1 M
scl-utils x86_64 1:2.0.2-14.el8 appstream 46 k
tcl x86_64 1:8.6.8-2.el8 baseos 1.1 M
Installing weak dependencies:
php81-php-fpm x86_64 8.1.0~rc6-1.el8.remi remi-safe 1.9 M
php81-php-mbstring x86_64 8.1.0~rc6-1.el8.remi remi-safe 490 k
php81-php-opcache x86_64 8.1.0~rc6-1.el8.remi remi-safe 418 k
php81-php-pdo x86_64 8.1.0~rc6-1.el8.remi remi-safe 140 k
php81-php-sodium x86_64 8.1.0~rc6-1.el8.remi remi-safe 93 k
php81-php-xml x86_64 8.1.0~rc6-1.el8.remi remi-safe 192 k
Transaction Summary
============================================================================
Install 13 Packages
Total download size: 10 M
Installed size: 35 M
Is this ok [y/N]: y
The extensions will be installed as below.
sudo dnf install php81-php-{curl,json,zip,fpm,gd,mysqlnd,devel,mcrypt,mbstring,xml,pear,bcmath,memcache,redis}
Check the installed version.
$ php81 --version
PHP 8.1.0 (cli) (built: Nov 23 2021 18:56:11) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies
Conclusion
That is it! We have triumphantly installed PHP 8.1 on AlmaLinux 8|Oracle Linux 8. I hope you learned a lot from this guide.