Setup and Upgrade PHP on RHEL Systems

This document describes a structured way to install and upgrade PHP and PHP-FPM on RHEL-compatible systems using the Remi repository.

This includes systems such as:

  • Red Hat Enterprise Linux (RHEL)
  • AlmaLinux
  • Rocky Linux
  • CentOS Stream

The focus is on a reproducible setup for production environments with current PHP versions and standard tooling.

What Is PHP

PHP is a server-side scripting language used to generate dynamic web content.
It is commonly used in:

  • Content Management Systems (CMS)
  • Web applications and APIs
  • Monitoring and analytics platforms
  • Custom backend systems

PHP remains widely deployed due to its ecosystem, stability, and broad hosting support.

PHP vs PHP-FPM

There are two common ways PHP is executed in web environments.

Traditional PHP (mod_php / embedded execution)

  • Runs directly inside the web server process
  • Simple architecture
  • Limited scalability and isolation

PHP-FPM (FastCGI Process Manager)

PHP-FPM runs PHP as a separate service outside the web server.

  • Dedicated process management
  • Better performance under load
  • Improved isolation between services
  • Works with Apache, Nginx, and other web servers

Key Difference

  • Embedded PHP ties execution to the web server process
  • PHP-FPM separates concerns and is the modern production standard

For any production system, PHP-FPM is the preferred approach.

Why Use the Remi Repository

RHEL-based distributions typically ship PHP through their official AppStream repositories.

Default Repository Limitations

The standard AppStream repositories focus on stability and therefore:

  • Ship older, stable PHP versions
  • Prioritize long-term support over feature updates
  • Lag behind upstream PHP releases

Remi Repository Advantages

The Remi repository is widely used in the RHEL ecosystem to provide:

  • Current PHP versions
  • Modular stream-based version switching
  • Faster release cycle compared to AppStream
  • Production-ready packages for enterprise systems

Trade-offs

  • Requires external repository configuration
  • Version management is explicit (module switching required)
  • Slightly more operational responsibility compared to base OS packages

In practice, Remi is the standard solution when you need modern PHP on RHEL-compatible systems.

PHP Installation on RHEL-Based Systems

This section covers a clean setup of PHP and PHP-FPM using the Remi repository on RHEL-compatible systems.

Prepare the System

Start with a fully updated base system:

sudo dnf update -y

Install basic tooling:

dnf install -y dnf-utils

Enable EPEL and Remi Repository

Install EPEL

sudo dnf install -y epel-release

Install Remi Repository

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E %rhel).rpm

How to Verify That PHP Streams Come From the Remi Repository

On AlmaLinux 9 (and other RHEL-compatible systems), PHP versions are managed via DNF modules. While this makes switching between versions simple, it also abstracts the underlying repository source.

List Available PHP Module Streams:

dnf module list php

Example output:

AlmaLinux 9 - AppStream
Name    Stream          Profiles                     Summary
php     8.1             common [d], devel, minimal   PHP scripting language
php     8.2             common [d], devel, minimal   PHP scripting language
php     8.3             common [d], devel, minimal   PHP scripting language

Remi's Modular repository for Enterprise Linux 9 - x86_64
Name    Stream          Profiles                     Summary
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
php     remi-8.2        common [d], devel, minimal   PHP scripting language
php     remi-8.3 [e]    common [d], devel, minimal   PHP scripting language
php     remi-8.4        common [d], devel, minimal   PHP scripting language
php     remi-8.5        common [d], devel, minimal   PHP scripting language

Hinweis: [d]Standard, aktivi[e]rt, [x]deaktiviert, [i]nstalliert

Reset any existing PHP module configuration:

sudo dnf module reset php -y

Enable the desired Remi PHP stream:

sudo dnf module enable php:remi-8.4 -y

Install PHP and PHP-FPM

Install core packages:

sudo dnf install -y php php-fpm

Install Common PHP Extensions

Typical extensions for web applications:

sudo dnf install -y \
php-cli \
php-common \
php-mysqlnd \
php-gd \
php-mbstring \
php-xml \
php-opcache \
php-pecl-apcu

Enable and Start PHP-FPM

sudo systemctl enable php-fpm
sudo systemctl start php-fpm

Check status:

systemctl status php-fpm

Verify Installation

Check PHP version:

php -v

PHP Upgrade on RHEL-Based Systems (Remi)

This section describes how to upgrade PHP safely on RHEL-compatible systems using the Remi repository.

Check Current State

PHP Version

php -v

Installed PHP Packages

rpm -qa | grep php

Compatibility Check

Before upgrading, verify application support:

  • WordPress: modern versions support PHP 8.x (recommended range depends on release)
  • Nextcloud: requires actively supported PHP 8.x versions
  • Matomo: recommends latest PHP 8.x for performance and memory efficiency

Always validate your application matrix before switching versions.

Check Available PHP Streams

sudo dnf module list php

Switch PHP Version (Remi Stream)

Reset Current Module:

sudo dnf module reset php -y

Enable New Stream

Example for a newer PHP version via Remi:

sudo dnf module enable php:remi-8.3 -y

Upgrade PHP Packages

sudo dnf upgrade -y php*

Restart Services

sudo systemctl restart php-fpm
sudo systemctl restart httpd

or if using Nginx:

sudo systemctl restart nginx
sudo systemctl restart php-fpm

Verify Upgrade

php -v

Check loaded modules:

php -m

Rollback Strategy (Important)

If something breaks after upgrade:
Re-enable previous stream

sudo dnf module reset php -y
sudo dnf module enable php: -y

Downgrade packages

sudo dnf downgrade php*

Notes

  • Always restart PHP-FPM after any version change
  • Clear opcode cache if needed (OPcache restart via service restart is usually sufficient)
  • Check logs:
journalctl -u php-fpm

Conclusion

This guide provides a practical baseline for installing and upgrading PHP and PHP-FPM on RHEL-based systems, including basic production hardening.

Advanced tuning, workload-specific optimization, and deeper performance analysis are intentionally out of scope and may be covered in separate articles.

In production, PHP-FPM should be reviewed and adjusted over time based on workload and system behavior.