Switching PHP Versions on AlmaLinux 9 with AppStream Modules
Learn how to switch PHP versions on AlmaLinux 9 using AppStream modular repositories with DNF, including a step‑by‑step example and key limitations.
31 May 2026, 05:00 UTC

Problem: Needing a Different PHP Version on AlmaLinux
Many web applications run on specific PHP releases, and a single AlmaLinux 9 server may need to host both legacy code that requires PHP 7.4 and newer projects that target PHP 8.1. Switching the system‑wide PHP version manually can lead to broken dependencies and missed security updates.
Thesis: AppStream Modules Let You Choose a Version Without Rebuilding
AlmaLinux 9 ships with the AppStream repository, which organizes packages into modular streams. Each stream represents a distinct version of a component (e.g., php:8.1) and can be enabled independently, letting DNF install that version and its dependencies while leaving other streams untouched.
How AppStream Modules Work
When you list modules with dnf module list, you see names like php, nodejs, or python together with available streams. Enabling a stream tells DNF to treat that stream as the default for the module.
Worked Example: Installing PHP 8.1
- Open a terminal with root or sudo privileges.
- Check what streams are available:
dnf module list php - Enable the 8.1 stream:
This step replaces the default PHP stream; any previously installed PHP packages from another stream will be marked for removal.sudo dnf module enable php:8.1 - Verify the enabled stream:
dnf module list --enabled | grep php - Install PHP from the module:
sudo dnf install php - Confirm the version:
should show a string starting withphp -vPHP 8.1.
Trade‑offs and Limitations
- Enabling a stream changes the default version; switching back may require removing the currently installed PHP packages first to avoid dependency conflicts.
- Third‑party repositories that provide non‑modular PHP packages can clash with AppStream streams, leading to unsatisfied dependencies.
- Only software that has been modularized in AppStream can be switched this way; extensions or libraries outside the module may still need manual handling.
Actionable Closing
If you need to run multiple PHP versions on the same host, consider using AppStream modules for the versions that are available, and isolate any remaining versions in containers or software collections. Always test the version switch in a staging environment and keep a record of the enabled streams so you can reproduce the setup later.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.