The Sanctuary

Writing about interests; Computer Science, Philosophy, Artificial Intelligence and more!

Installing PHP 8.2 on RHEL 9

phprhellinuxsysadmin

My RHEL 9 setup came with PHP 8.0.27, which is halfway to its EOL (End of Life). PHP 8.0 reached end of life in November 2023, meaning no more security updates. Not to mention that I require the latest PHP version available for modern framework support and performance improvements.

In this article, we’ll upgrade to PHP 8.2 using the EPEL and Remi repositories.

Why Upgrade to PHP 8.2?

PHP 8.2 brings several improvements over 8.0:

  • Readonly classes - Declare entire classes as readonly
  • Disjunctive Normal Form (DNF) Types - Combine union and intersection types
  • null, false, and true as standalone types
  • Random Extension - New object-oriented API for random number generation
  • Deprecated dynamic properties - Better code quality enforcement
  • Performance improvements - Continued optimization from the JIT compiler

Prerequisites

Before proceeding, ensure you have:

  • RHEL 9 with sudo access
  • An active subscription or configured repositories

Step 1: Enable EPEL Repository

Extra Packages for Enterprise Linux (EPEL) is a Special Interest Group (SIG) from the Fedora Project that provides additional high-quality packages for RHEL and compatible distributions.

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y

Step 2: Enable Remi Repository

The Remi repository is maintained by Remi Collet, a Fedora packager. It provides the latest versions of PHP and related packages, making it the go-to source for PHP on RHEL-based systems.

sudo dnf install dnf-utils https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y

Step 3: Install PHP 8.2

First, list available PHP module streams to see your options:

sudo dnf module list php

You’ll see multiple versions available from different repositories. Enable the Remi PHP 8.2 module:

sudo dnf module enable php:remi-8.2 -y

If you have an existing PHP installation, you may need to reset the module first:

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

Now install PHP:

sudo dnf install php -y

Step 4: Install Common Extensions

You’ll likely need additional PHP extensions. Here are some commonly required ones:

sudo dnf install php-cli php-fpm php-mysqlnd php-pdo php-gd php-mbstring php-xml php-curl php-zip php-intl php-opcache -y

Step 5: Verify Installation

Confirm PHP 8.2 is installed correctly:

php -v

Expected output:

PHP 8.2.x (cli) (built: ...)
Copyright (c) The PHP Group
Zend Engine v4.2.x, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.x, ...

Check loaded modules:

php -m

Configuring PHP-FPM (Optional)

If you’re using PHP-FPM with Nginx or Apache:

# Start and enable PHP-FPM
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

# Check status
sudo systemctl status php-fpm

The main configuration file is located at /etc/php-fpm.d/www.conf.

Troubleshooting

Module conflicts: If you encounter conflicts with the default PHP module, reset it first:

sudo dnf module reset php

Missing extensions: Search for available extensions:

dnf search php- | grep 8.2

SELinux issues: If PHP-FPM fails to start, check SELinux:

sudo setsebool -P httpd_execmem 1

Conclusion

Upgrading PHP on RHEL 9 is straightforward with the Remi repository. You now have access to the latest PHP features and security updates. Remember to test your applications after upgrading and update your composer.json to reflect the new PHP version requirement.


Installing PHP 8.2 on RHEL 9

A step-by-step guide to upgrading PHP using the Remi repository.

Achraf SOLTANI — April 28, 2023