Guides 11792 Published by

This guide walks you through installing PHP 8.x and older streams on CentOS Stream EL9 or EL8 by first disabling conflicting RHEL modules, then adding Remi’s repository that hosts every PHP major version. After enabling the dnf‑plugins‑core (or yum‑plugin‑modulemd) package, you enable the specific remi‑php stream for your desired release—such as 8.2, 8.1, 8.0 or 7.4—and install the core php packages together with common extensions like mysqlnd, json, zip, gd, curl, mbstring and opcache. A quick sanity check shows the correct version with `php -v`, while `systemctl enable --now php‑fpm` launches the FastCGI process manager and a simple info.php file confirms everything is wired up; the article also highlights a real‑world issue where omitting php-mbstring caused Drupal errors, illustrating why that extension matters. Finally, it covers optional side‑by‑side version switches, SELinux adjustments for writable directories, and firewalld rules to keep HTTP/HTTPS traffic flowing—ensuring your CentOS Stream box is ready for any PHP project.



How to Install PHP 8.2 (and 8.1, 8.0, 7.4) on CentOS Stream EL9 or EL8

If you’ve got a fresh CentOS Stream box and need a specific PHP flavor for an old project or a new one, this guide will get the right version up and running fast. It covers both EL8 (CentOS 8/RHEL 8) and EL9 (CentOS 9 Stream/RHEL 9), using the Remi repository because that’s the only place you can grab all the recent streams without fighting with the system modules.

What You’ll Learn
  • How to enable the proper remi‑php stream for each PHP version
  • Why you need dnf-plugins-core or yum-plugin-modulemd
  • A quick checklist for getting php-fpm and common extensions ready
  • A real-world tweak that saved a site from crashing after an upgrade
Prerequisites: Clean Slate, No Conflicting Modules

On EL8 you’ll see a lot of pre‑installed “modules” (the old RHEL Module Stream thing). If you let them run, they can pull in the wrong PHP version or block Remi. Run:

sudo dnf module list php | grep enabled

If anything shows up, disable it first:

sudo dnf module reset php -y

For EL9 the same applies, but the command is identical because dnf handles modules uniformly.

Step 1: Install the Remi Repository

The official CentOS repos no longer ship PHP 8.x. Remi’s repo bundles every stream you might need.

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm   # EL9
# or
sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm   # EL8

> Remi keeps a separate package for every PHP major version, so you can pick exactly the one you want.

Step 2: Enable dnf‑plugins‑core (or yum‑plugin‑modulemd)

This gives us the dnf config-manager command to enable remi‑php streams without editing files manually.

sudo dnf install -y dnf-plugins-core          # EL9
# or
sudo yum install -y yum-plugin-modulemd       # EL8
Step 3: Enable the Desired PHP Stream

Pick your version and enable it:

PHP Command (EL9) Command (EL8)
8.2 sudo dnf module enable php:remi-php82 -y same, but yum
8.1 sudo dnf module enable php:remi-php81 -y same
8.0 sudo dnf module enable php:remi-php80 -y same
7.4 sudo dnf module enable php:remi-php74 -y same

> The module enable step tells the package manager to pull from Remi’s stream instead of the default one. If you forget this, you’ll end up with PHP 7.2 or an older build that ships in CentOS.

Step 4: Install PHP and Common Extensions
sudo dnf install -y php php-fpm php-cli php-mysqlnd \
                    php-json php-zip php-gd php-curl php-mbstring \
                    php-opcache php-fileinfo
  • php-fpm is the FastCGI process manager most modern stacks use.
  • The extensions listed cover MySQL, JSON, ZIP, GD for images, cURL for HTTP, mbstring for multibyte support (very common in non‑English sites), and opcache to speed up PHP.
Step 5: Verify the Installation
php -v

You should see something like:

PHP 8.2.5 (cli) (built: Jan 10 2024 12:34:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies

If the version number doesn’t match, double‑check that the module was enabled and no conflicting package is installed.

Step 6: Start and Enable php‑fpm
sudo systemctl enable --now php-fpm

Test it by creating a quick info.php in /var/www/html:

<?php phpinfo(); ?>

Open that page in your browser. If you see the PHP info table, everything is wired correctly.

Real‑World Tweak: The Missing mbstring Problem

I once upgraded a Drupal 8 site from PHP 7.3 to 8.0 on EL9 and watched it spit out “Undefined function mb_strlen()” errors. The culprit? php-mbstring wasn’t installed because I only pulled the base php package. Installing it fixed the issue in seconds. Don’t skip that extension unless you know for sure you won’t need multibyte handling.

Optional: Switching Between Versions

If you need multiple PHP versions side‑by‑side (e.g., for different projects), just enable the other stream and install its php package with a version suffix:

sudo dnf module enable php:remi-php81 -y
sudo dnf install -y php81

Then point Apache or Nginx to the desired PHP‑FPM socket in your vhost config.

Gotchas & Quick Fixes
  • Package conflicts – If you get “conflicts with module php:remi-php82” errors, make sure all previous php modules are reset first.
  • SELinux – On EL9, if PHP scripts can’t write to /var/www/html, run sudo setsebool -P httpd_enable_homedirs 1 or adjust the context with chcon.
  • Firewall – If you’re running a web server behind firewalld, remember to open HTTP/HTTPS ports: firewall-cmd --permanent --add-service=http; firewall‑cmd --reload.

That’s it. Grab the right stream from Remi, enable it, install PHP and the usual extensions, and your CentOS Stream machine will be ready for any project that needs PHP 8.x or 7.4.