Complete uninstall and re-install of PHP on Centos 7
Running multiple PHP versions side-by-side on CentOS 7 is a common requirement for legacy support or testing, but it often leads to repository conflicts when you attempt to revert changes. The scenario described involves attempting to run older versions like PHP 5.5 or 5.6 over an existing installation of PHP 7.1 using the REMI repository. While enabling these sub-repos allows yum to install older packages, the process of disabling them and trying to "switch back" frequently results in a broken state where package metadata becomes inconsistent with the actual installed binaries.
The symptoms describedâwhere php -v reports version 7.2.14 but <? phpinfo() ?> renders content from version 7.1.24âindicate that the PHP-FPM or Apache modules are pointing to a different binary than the CLI tool. This divergence usually happens because the uninstall process did not fully clean up the symbolic links or configuration files associated with the previous version, while yum updated the package list to reflect the newer REMI packages.
Diagnosing the Broken State
Before attempting a reinstall, it is crucial to understand why the standard "disable repo and remove" workflow failed in this case. The error message regarding the missing MySQL extension is misleading; the system actually has php-mysqlnd installed (as seen in the output), which obsoletes the older php-mysql. WordPress checks for the presence of a PDO or mysqli handler, but if the web server is loading an incompatible module or if the SAPI (Server API) configuration is mismatched, it may fail to detect the extension correctly.
To fix this without a full system wipe, you must ensure that all artifacts of the conflicting versions are removed. Simply disabling the REMI repositories leaves orphaned packages that yum cannot manage cleanly. You need to force an erasure of these specific packages.
The Cleanup Process
Execute the following commands to remove the conflicting PHP packages. This targets the specific versioning strings often left behind when switching between REMI sub-versions:
sudo yum erase php-cli php-common php-fpm php-gd php-json php-mysqlnd php-pdo php-pecl-mcrypt -y
If you installed these versions using a dedicated .tar.gz archive or source code, those binaries must also be deleted from /usr/bin/php*, /usr/lib64/php/modules/, and the configuration directory in /etc/php*.conf.d. The phpinfo() output discrepancy suggests that web server modules are still pointing to old paths. Check your Apache or Nginx configuration files (typically in /etc/httpd/conf.d/ or via the PHP-FPM pool definition) to ensure they are loading the correct SAPI.
Reinstalling with Consistency
Once the system is cleared, re-enable only the repository for the desired version. If you intend to return to the original stable setup, ensure that the main REMI repo or the Webtatic repo is correctly configured and enabled. Run:
sudo yum install php php-cli php-fpm php-mysqlnd php-gd php-json -y
After installation, verify that the CLI and the web server are reporting the same version:
php -v
curl http://localhost/phpinfo.php | grep "PHP Version"
If you require multiple versions again, do not rely on a single repository configuration to handle everything simultaneously without careful isolation. Consider using php-build or Docker containers for isolated environments rather than mixing REMI sub-repos, which can lead to the exact kind of version mismatch observed in your logs.
Why This Happens
The core issue stems from how RPM packages manage dependencies and metadata. When you install PHP 5.6 over PHP 7.1, the files occupy different paths or overwrite specific modules depending on the build flags. Disabling the repo does not retroactively change those file paths or update the configuration directives that point to them. The "missing extension" error in WordPress is likely a false positive triggered by the web server loading an older module that lacks the necessary mysqli stubs, even if php-mysqlnd exists for the CLI.
By forcing a complete erase of the conflicting packages and reinstalling with a single, consistent repository state, you align the binary paths, the SAPI modules, and the extension libraries. This ensures that both the command line and the web server interpret the PHP version identically.