How to install PHP module intl on Ubuntu 22.04 with both PHP 8.1 and PHP 8.2 active
WordPress health checks frequently flag the intl extension as a potential improvement, especially when running on shared hosting or specific server configurations where extensions are compiled into specific PHP versions but not globally available. The immediate reaction is often to run apt-get install -y php-intl. However, on Ubuntu 22.04 systems configured with multi-version PHP stacksâspecifically maintaining both PHP 8.1 and PHP 8.2 active simultaneouslyâyou will encounter dependency errors that prevent a straightforward installation.
The error message typically indicates a version mismatch: php8.1-intl expects php8.1-common at version 8.1.2-1ubuntu2.10, but the system holds or is attempting to install a different version, such as 8.1.14-1+ubuntu18.04.1+deb.sury.org+1. This discrepancy usually arises when your server uses OndÅej Surý's repository (managed by phpsury.org) for PHP 8.2 while relying on the default Ubuntu repositories for PHP 8.1, or vice versa. The package manager refuses to mix these incompatible binary blobs, resulting in a "broken packages" state that blocks the installation.
To resolve this without breaking your existing multi-PHP environment, you must install the specific extension package for the exact PHP version and architecture required by your application. Unlike some Linux distributions where php-intl is a generic meta-package, Ubuntu differentiates extensions by major version number in its package naming convention.
If your application logic or .htaccess configuration dictates that PHP 8.1 is the active runtime (as suggested by the presence of imagick installed for php8.1), you need to target that specific minor version. Run the following command to install the module directly for PHP 8.1:
apt-get install -y php8.1-intl
This approach bypasses the generic php-intl meta-package, which attempts to resolve dependencies across all installed PHP versions and fails when the base common files do not match the expected repository versioning. By specifying php8.1-intl, you ensure that the C-extensions are compiled against the correct php8.1-common library files currently residing in your system's libraries, regardless of whether PHP 8.2 is also installed on the same node.
Alternatively, if your application logic has been updated to run exclusively on PHP 8.2 and you intend to deprecate the older version, you should switch your source code execution context to PHP 8.2 first. Once cli or fpm is pointing to version 8.2, you can install the module for that specific version:
apt-get install -y php8.2-intl
Before finalizing the installation, it is crucial to verify which PHP version your web server is actually using. You can check this by running php -v after ensuring your sudo update-alternatives or web server configuration points to the desired version. If you are managing a production environment where both versions must coexist side-by-sideâfor instance, serving legacy applications on 8.1 and new ones on 8.2âensure that each application directory explicitly calls the correct PHP binary via php73, php81, or php82 wrappers to avoid mixing extension states.
Remember that installing extensions for one PHP version does not automatically enable them for another, even if they share the same underlying operating system libraries. Each major PHP version on Ubuntu maintains its own isolated set of compiled modules. Therefore, precision in package naming is not just a suggestion; it is a requirement to avoid dependency hell and ensure your WordPress health check remains clear.