Thanks to Remi Collet for clearing up the confusion between installing PHP extensions for single PHP installations and multiple version PHP installations.
In this case, on AlmaLinux 8 (Centos 8 compatible) system, with a single PHP installation, logged in as root user.
First verify single PHP installalation:
> locate bin/php
/usr/bin/php
/usr/bin/php-cgi
/usr/bin/phpize
/usr/sbin/php-fpm
Indeed, a single PHP installation.
For additional troubleshooting, determine the location of the PHP extension modules and configuration files. Searching /etc/php.ini reveals:
;;;;
; Note: packaged extension modules are now loaded via the .ini files
; found in the directory /etc/php.d; these are loaded by default.
;;;;
Notice PHP is looking in /etc/php.d for an extension module configuration file. Attempt to list the extension module and it's configuration file:
> ls -la /usr/lib64/php/modules/ | grep dom.so
> ls -la /etc/php.d/ | grep dom.ini
Is there a config file in the /etc/php.d directory? If so, read it to see what directory PHP is looking for the extension in, and compare that to /usr/lib64/php/modules/dom.so.
If there is no config file for that extension in /etc/php.d that's why PHP is not loading the extension.
There are two options if you have a version specific extension loaded, 1) (not recommended) is to move the config file to the /etc/php.d directory and make sure it points to the module location, or, 2) (recommended) is to remove the previous extension installation and use the proper repository and package to install it.
To properly install a PHP extension module for single PHP installation...
...start by listing the system's current repo status (in pertinent part):
> dnf repolist all
repo id repo name status
apprepo apprepo enabled
appstream AlmaLinux 8 - AppStream enabled
baseos AlmaLinux 8 - BaseOS enabled
epel Extra Packages for Enterprise Linux 8 - x86_64 enabled
extras AlmaLinux 8 - Extras enabled
powertools AlmaLinux 8 - PowerTools enabled
remi Remi's RPM repository for Enterprise Linux 8 - x86_64 disabled
remi-safe Safe Remi's RPM repository for Enterprise Linux 8 - x86_64 enabled
Is PowerTools enabled? (AlmaLinux 8 comes with powertools installed.)
powertools AlmaLinux 8 - PowerTools enabled
...yes. However, if not enabled:
> dnf config-manager --set-enabled powertools
Is epel repo installed and enabled? In this case yes, but if not:
> dnf install epel-release
Is remi repo installed and enabled? In this case yes, but if not:
> dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
> dnf config-manager --set-enabled remi
Now simply:
> dnf install php-dom
> systemctl restart nginx
> systemctl restart php-fpm
And verify:
> php -m | grep dom
dom
phpexecutable is linked with some other version than 8.1 What doesphp -vshow? Can you also tryphp81 -m | grep dom