Guides 11792 Published by

This article explains how to upgrade a Rocky Linux web stack to PHP 8.2 using the Remi repository and provides preflight checks such as ensuring sudo access, a clean system, and removal of old PHP packages. It details step‑by‑step commands for both EL9 and EL8, showing how to reset and enable the correct PHP stream, install core modules like php-cli, php-fpm, and php-mysqlnd, and verify the installation with `php -v`. The guide also clarifies why each command matters—resetting modules clears conflicts, enabling Remi pulls the latest builds, and removing older packages prevents symbol collisions. A troubleshooting table lists common symptoms such as lingering old module activations or missing extensions, provides fixes, and concludes with a reminder to double‑check repo settings before retrying.



Install PHP 8.2 on Rocky Linux EL9 or EL8

If you’re running a web stack on Rocky Linux and want the newest language features, this quick guide shows how to drop PHP 8.2 into place—no surprise updates, just straight‑forward steps.

Pre‑flight checklist
  • Your user has sudo privileges.
  • The machine is freshly updated (sudo dnf update).
  • No existing PHP 7.x or older packages that could conflict remain in the system (you’ll clean those out later).
Installing on Rocky Linux 9 (EL9)

Rocky 9 ships with PHP 8.1 by default, so pulling 8.2 is a one‑liner with the Remi repo.

# Install the Remi repository
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm

# Enable the PHP 8.2 stream and install
sudo dnf module reset php:*
sudo dnf module enable php:8.2
sudo dnf install -y php php-cli php-fpm php-mysqlnd

# Verify
php -v

Why each step matters:

  • Step 1 gives you access to the newest PHP builds that Rocky’s base repos won’t ship.
  • Step 2 tells DNF which stream (8.2) to pull instead of the default 8.1; the module reset clears any old stream configuration so nothing gets double‑installed.
  • Step 3 confirms you’re actually running 8.2 and that the CLI binary is in your PATH.

Once you see something like PHP 8.2.x …, you’re good to go. If you use Apache, install mod_php instead of php-fpm; for Nginx stick with FPM.

Installing on Rocky Linux 8 (EL8)

Rocky 8 is a little trickier because its base repos only offer PHP 7.x. Here’s the Remi recipe that works like a charm:

# Install dnf‑plugins-core to manage modules
sudo yum install -y dnf-plugins-core

# Enable the Remi repo (make sure it’s the RHEL8 version)
sudo yum-config-manager --enable remi-php82

# Remove any old PHP packages that might clash
sudo yum remove -y php\ php-cli\

# Install PHP 8.2 and common extensions
sudo yum install -y php php-cli php-fpm php-mysqlnd

# Check the version
php -v

Why those commands:

  • Step 1 brings in yum-config-manager so we can toggle repos on demand.
  • Step 2 tells YUM to pull from Remi’s PHP 8.2 stream—without this, you’d still end up with 7.x.
  • Step 3 clears out the old 5‑plus or 7‑plus packages that could cause symbol collisions.
  • Step 4 installs the core runtime plus FPM; add php-gd, php-xml, etc., as your project demands.

After step 5 you should see a line like PHP 8.2.x (cli) …. If not, double‑check that Remi’s repo is enabled (yum repolist).

Common pitfalls & fixes
Symptom Likely cause Fix
php -v shows 7.4 or 8.1 Old module still active Run sudo dnf module reset php:*; sudo dnf module enable php:8.2 (EL9) or yum-config-manager --disable remi-php82 then re‑enable it.
PHP extensions missing (php-mysqlnd not found) Remi repo disabled Re‑run the enable step for the correct PHP stream.
Apache complains “mod_php is not installed” You installed FPM, but use Apache Install sudo yum install php-mod_php or switch to Nginx/FPM.

I once had a server that kept refusing a Laravel 10 deploy because it was silently falling back to PHP 7.4; the culprit turned out to be a leftover module definition from an old CentOS 7 migration. Resetting the module and enabling the new stream solved everything in seconds.

That’s all there is to it—no fancy build scripts, just straight package installs. If you hit snags, check that the correct Remi repo is enabled for your version of Rocky, clean any old PHP packages, then retry.