In this short blog post we will be focused on how to install PHP 8.1 on Rocky Linux 8|CentOS 8. PHP is a very powerful and open source, server scripting language created to make creation of dynamic and interactive Web pages an interesting journey. PHP is an alternative to competitors such as Microsoft’s ASP. This programming language was originally created by Danish-Canadian programmer, named Rasmus Lerdorf, in 1994.
PHP 8.1 is an update from its predecessor release PHP programming language version 8.0. If you’re ready to test this new release of PHP then this article is for you. The most powerful content management systems such as Drupal, WordPress, and Joomla are powered by PHP. PHP 8.1 comes with set of new features, performance improvements, changes and deprecations.
New features in PHP 8.1
- Enums – They are now added in PHP 8.1
- Readonly properties – Class properties can be marked as readonly hence can only be written once
- Never Return Type – A new return type hint called never is added in PHP 8.1
- Support for DNS-over-HTTPS (DoH)
- AVIF Image Format support – The PHP 8.1’s image processing and GD extension adds support for AVIF images.
- Added support for Fibers – The low level mechanism to manage parallelism
- File Uploads with CURLStringFile – In PHP 8.1, PHP Curl extension now supports HTTP(S) requests with file uploads
- Addition of pure intersection types feature
- PHP 8.1 adds array_is_list as a built-in function
- Explicit Octal Numeral Notation
- New fdatasync() and fsync() Functions
- Define final Class Constants
- Among many other new features and deprecations
In the next sections we will focus on a step-by-step installation of PHP 8.1 on Rocky Linux 8|CentOS 8. RHEL 8 based systems ships with some versions of PHP, available in AppStream repositories which can be checked with the following command:
$ sudo dnf module list php
Last metadata expiration check: 0:00:05 ago on Sat 20 Nov 2021 10:32:10 AM UTC.
Rocky Linux 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
For PHP 8.1, we’ll use Remi RPM repositories which contains the new packages of PHP for RHEL based systems such as CentOS, Rocky Linux, AlmaLinux, Fedora e.t.c.
Step 1 – Add Remi YUM repository to Rocky / CentOS system
We need to enable EPEL repository before adding Remi YUM repos to our system.
sudo dnf -y install epel-release
sudo dnf config-manager --set-enabled powertools
After EPEL and PowerTools repositories are added to the system, proceed to enable Remi YUM repository:
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Confirm all the repositories added are active:
$ sudo dnf -y makecache
$ sudo dnf -y repolist
repo id repo name
appstream Rocky Linux 8 - AppStream
baseos Rocky Linux 8 - BaseOS
epel Extra Packages for Enterprise Linux 8 - x86_64
epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64
extras Rocky Linux 8 - Extras
powertools Rocky Linux 8 - PowerTools
remi-modular Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe Safe Remi's RPM repository for Enterprise Linux 8 - x86_64
There should be new PHP modules added to the system
$ sudo dnf module list php
Last metadata expiration check: 0:00:05 ago on Sat 20 Nov 2021 10:32:10 AM UTC.
Rocky Linux 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
Step 2 – Install PHP 8.1 on Rocky Linux 8|CentOS 8
With the required repositories enabled and confirmed to be working, we can now install PHP 8.1 on Rocky Linux 8|CentOS 8.
Let’s reset the PHP default module in AppStream repository:
sudo dnf -y module reset php
Enable Remi repository for PHP 8.1 by running the command below as sudo user:
sudo yum module install php:remi-8.1
Confirm package dependencies and proceed with the installation of PHP 8.1 from Remi repository
Dependencies resolved.
======================================================================================================================================================================================================
Package Architecture Version Repository Size
======================================================================================================================================================================================================
Installing group/module packages:
php-cli x86_64 8.1.0~RC6-1.el8.remi remi-modular 5.3 M
php-common x86_64 8.1.0~RC6-1.el8.remi remi-modular 1.2 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-xml x86_64 8.1.0~RC6-1.el8.remi remi-modular 249 k
Installing dependencies:
httpd-filesystem noarch 2.4.37-43.module+el8.5.0+714+5ec56ee8 appstream 38 k
libxslt x86_64 1.1.32-6.el8 baseos 249 k
oniguruma5php x86_64 6.9.7.1-1.el8.remi remi-safe 210 k
Installing weak dependencies:
nginx-filesystem noarch 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 23 k
Installing module profiles:
php/common
Enabling module streams:
httpd 2.4
nginx 1.14
php remi-8.1
Transaction Summary
======================================================================================================================================================================================================
Install 9 Packages
Total download size: 9.7 M
Installed size: 45 M
Is this ok [y/N]: y
You’re asked to accept importation of some package signing GPG keys during installation.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 12 MB/s | 9.7 MB 00:00
Remi's Modular repository for Enterprise Linux 8 - x86_64 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
Let’s see the version of PHP installed on our system:
$ php --version
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
Step 3 – Install PHP 8.1 Extensions on Rocky Linux 8|CentOS 8
PHP extensions helps you to avoid having to recreate the same code for numerous PHP applications from scratch. You install an extension and simply connect it to it from your application. You can easily make use of a publicly available extension which can be installed with the command syntax:
sudo yum install php-xxx
- Where xxx is the extension name.
Here are the commands to install commonly used PHP extensions:
sudo dnf install php php-cli php-{curl,json,zip,fpm,gd,mysqlnd,devel,mcrypt,mbstring,xml,pear,bcmath,memcache,redis}
Accept installation prompt to proceed:
Transaction Summary
======================================================================================================================================================================================================
Install 73 Packages
Total download size: 78 M
Installed size: 208 M
Is this ok [y/N]: y
Checking all available PHP extensions:
$ php --modules
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
json
libxml
mbstring
mcrypt
memcache
msgpack
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
Step 4 – Running multiple versions of PHP
Software Collection is the best way to run multiple versions of PHP. The php81 collection is available in the remi-safe repository and can be installed with the command:
sudo dnf install php81
Additional additional packages can be installed by using the command:
sudo dnf install php81-php-xxx
Checking PHP 8.1 version
$ php81 --version
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
Listing enabled modules for PHP 8.1
$ php81 --modules
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zlib
[Zend Modules]
Zend OPcache
This concludes our guide on how to install PHP 8.1 on Rocky Linux 8|CentOS 8. We hope you enjoyed and always welcome. For any issues encountered during the installation, don’t hesitate to contact us in the comments section or email. Cheers!