Guides 11792 Published by

This quick guide shows how to replace AlmaLinux 9’s default PHP 7.4 with the newer PHP 8.1 from Remi’s repository, which is essential for modern frameworks like Laravel 10 or WordPress themes that need PHP 8.0+. It walks you through enabling EPEL and Remi repos, disabling the built‑in PHP module, turning on the remi-php81 stream, then installing PHP 8.1 along with common extensions such as CLI, FPM, MySQLnd, ZIP, GD, cURL, JSON, PDO, and mbstring. The tutorial also tells you how to verify the installation by checking the command‑line version or viewing a phpinfo page on your web server. Finally, it lists quick fixes for typical issues like missing remi‑php81 packages, leftover PHP modules, or FPM startup failures.



Install PHP 8.1 on AlmaLinux 9

In this quick guide you’ll learn how to drop the old default PHP that ships with AlmaLinux 9 and replace it with the fresh, feature‑rich PHP 8.1—ready for your modern web apps or local development stack.

Why swap out the stock PHP?

AlmaLinux 9 ships with PHP 7.4 in its base repositories. If you’re running a Laravel 10 site, a WordPress theme that relies on PHP 8.0+, or just want the performance boost of the new JIT engine, you’ll need to upgrade yourself. I’ve seen sites crash after an automatic update that left them stuck with legacy modules; swapping to Remi’s build is the cleanest fix.

Step 1: Enable the EPEL and Remi repositories
sudo dnf install -y epel-release
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm

EPEL gives you a sandbox of extra packages, while Remi’s repo hosts the latest PHP builds that aren’t in AlmaLinux’s default repos. Without these two, dnf won’t see PHP 8.1.

Step 2: Disable the built‑in PHP module
sudo dnf module disable -y php

AlmaLinux loads its own PHP module by default; if you try to install a different version, DNF will complain about conflicts. Turning off the module clears that roadblock.

Step 3: Enable Remi’s PHP 8.1 stream
sudo dnf config-manager --set-enabled remi-php81

This tells DNF to pull packages from the PHP 8.1 branch of Remi, not the older branches or the base repo.

Step 4: Install PHP 8.1 and common extensions
sudo dnf install -y php php-cli php-fpm php-mysqlnd \
                     php-zip php-gd php-curl php-json php-pdo php-mbstring

Why this matters:

php pulls the core interpreter, php-fpm is what most web servers use to serve PHP. The rest are the extensions that most projects expect—MySQL support, JSON handling, image manipulation, etc. Skipping any of them will leave you chasing “undefined function” errors later.

Step 5: Verify everything worked
php -v

You should see something like:

PHP 8.1.x (cli) (built: ...)
Copyright ...

And if you’re running a web server, check /var/www/html/info.php with <?php phpinfo(); ?>. The page should report PHP 8.1 as the version.

Common hiccups and quick fixes
  • “Module “remi‑php81” not found” – make sure you typed the URL correctly when installing Remi, and that the repo file ends with .repo in /etc/yum.repos.d/.
  • Dependency errors – sometimes a leftover php package from the default module sticks around. Run sudo dnf remove php\ before reinstalling to clear any clutter.
  • PHP‑FPM not starting – check /usr/lib/systemd/system/php-fpm.service. If it fails, look at /var/log/messages for missing modules.

That’s all there is to it. Swap out the stock PHP and you’ll be running a modern stack without breaking your AlmaLinux system.