How to install PHP 8 on CentOS 8 Linux

Updated on February 16, 2022

This tutorial will explain how to install PHP 8 on CentOS 8 Linux and its dependent packages.

Step 1: Enableremi-release-8.rpm

Configure the Remi repository for installing PHP 8 on CentOS 8

# dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Step 2: Enable EPEL repository

# dnf install epel-release

Step 3: Find the current enabled version of PHP

# dnf module list php
CentOS Stream 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
php 8.0 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 4: Enable the module PHP8.1 from remi

From the above output, by default PHP 7.2 from the AppStream repo shall be installed and no other version is enabled. To install PHP 8.1 from the remi repo, enable it before installation.

# dnf module enable php:remi-8.1
# dnf module list php
CentOS Stream 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
php 8.0 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 [e] common [d], devel, minimal PHP scripting language
Switch to the other version?

In case, if you need to install any other version, you can reset the current module enabled and set the new using the below commands:

# dnf module reset php

# dnf module enable php:remi-8.0

Step 5: Install PHP 8 on CentOS 8

# dnf install php

Last metadata expiration check: 0:13:44 ago on Wed 16 Feb 2022 11:53:53 AM IST.
Dependencies resolved.
=============================================================================================================================================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================================================================================================================================
Installing:
php x86_64 8.1.2-1.el8.remi remi-modular 1.7 M
Installing dependencies:
apr x86_64 1.6.3-12.el8 appstream 129 k
apr-util x86_64 1.6.1-6.el8 appstream 105 k
centos-logos-httpd noarch 85.8-2.el8 baseos 75 k
httpd x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 appstream 1.4 M
httpd-filesystem noarch 2.4.37-43.module_el8.5.0+1022+b541f3b1 appstream 39 k
httpd-tools x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 appstream 107 k
libsodium x86_64 1.0.18-2.el8 epel 162 k
libxslt x86_64 1.1.32-6.el8 baseos 250 k
mailcap noarch 2.1.48-3.el8 baseos 39 k
mod_http2 x86_64 1.15.7-3.module_el8.4.0+778+c970deab appstream 154 k
oniguruma5php x86_64 6.9.7.1-1.el8.remi remi-safe 210 k
php-common x86_64 8.1.2-1.el8.remi remi-modular 1.2 M
Installing weak dependencies:
apr-util-bdb x86_64 1.6.1-6.el8 appstream 25 k
apr-util-openssl x86_64 1.6.1-6.el8 appstream 27 k
nginx-filesystem noarch 1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream 24 k
php-cli x86_64 8.1.2-1.el8.remi remi-modular 5.3 M
php-fpm x86_64 8.1.2-1.el8.remi remi-modular 1.8 M
php-mbstring x86_64 8.1.2-1.el8.remi remi-modular 522 k
php-opcache x86_64 8.1.2-1.el8.remi remi-modular 628 k
php-pdo x86_64 8.1.2-1.el8.remi remi-modular 160 k
php-sodium x86_64 8.1.2-1.el8.remi remi-modular 100 k
php-xml x86_64 8.1.2-1.el8.remi remi-modular 250 k
Enabling module streams:
httpd 2.4
nginx 1.14

Transaction Summary
=============================================================================================================================================================================================================================================
Install 23 Packages

Step 6: Verify the PHP installation

# php -v
PHP 8.1.2 (cli) (built: Jan 18 2022 23:52:03) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

That’s It! Enjoy PHP coding 🙂

Was this article helpful?

Related Articles

Comments Leave a Comment

Leave a Comment