How to uninstall an older PHP version from CentOS 7
Upgrading a legacy stack on CentOS 7 often hits a wall when package managers refuse to install newer dependencies due to conflicting versions of core libraries. The scenario described involves a project requiring PHP 5.5 or higher, yet the system is stuck with PHP 5.4 installed via YUM. When you attempt to resolve missing extensions like php-pdo, the transaction fails immediately because the package manager detects a conflict between php56w-common and php-common-5.4.16. This is not a configuration error; it is a version lockout caused by overlapping EPEL (Extra Packages for Enterprise Linux) repositories or user-installed packages that haven't been cleanly removed.
To proceed, you must first identify exactly which PHP variants are occupying the system's namespace. CentOS 7 ships with PHP 5.4 by default, but many users install the Remi repository to access newer versions like 5.6. If both repositories are active and a partial upgrade has occurred, you will see multiple php-* packages coexisting in /usr/bin/php. Running yum list installed php* will reveal the specific versions installed. You likely have php-common-5.4, php-mysqlnd-5.4, and perhaps a partially installed php-common-5.6.
The error conflict between php56w-common and php-common-5.4.16 indicates that the newer package depends on a specific version of the common library that does not exist, while the older package is still blocking the namespace. You cannot simply yum install php-pdo because the dependency resolver sees this as an unsafe state. The solution requires explicitly removing the older packages before the newer ones can be fully integrated.
Execute the following command to remove the conflicting 5.4 packages:
sudo yum remove php-common-5.4.* php-mysqlnd-5.4.* php-cli-5.4.*
You may need to list all installed sub-packages first using yum list installed | grep 'php-5.4' to ensure you catch every variant, including php-fpm, php-gd, or php-curl. Once the 5.4 packages are gone, verify that no remnants exist in /usr/bin/php. If a symlink points to the old version, remove it manually:
sudo rm /usr/bin/php
After clearing the path, update your package metadata to ensure YUM has the latest view of available repositories:
sudo yum clean all
sudo yum makecache
Now you can attempt to install the PDO driver again. If you are using the Remi repository, use the specific command for that version:
sudo yum install php56w-pdo
If you prefer to stick with the system defaults or a different EPEL build, ensure your php.ini file reflects the correct extension paths. A common pitfall after uninstalling old versions is forgetting to update the extension=pdo_mysql.so line in /etc/php.ini. The path to this file changes depending on whether you are using CLI (/etc/php.cli.ini) or FPM. Verify that the pdo_mysql extension is actually loaded by running php -m | grep pdo.
If you continue to encounter issues where packages refuse to install despite being removed, check for orphaned dependencies with yum deplist php-common. Sometimes, removing the main package leaves behind libraries in /usr/lib64/php/5.4 that prevent new installations. Clearing these directories:
sudo rm -rf /usr/lib64/php/5.4/*
is a drastic but necessary step if the conflict persists.
Once the environment is clean, proceed with installing php-common-5.6 or the specific version required by your Laravel 5.2 application. Ensure that your Apache or Nginx configuration points to the new PHP binary and not the old one. If you are using a custom setup where you previously compiled PHP from source, ensure those binaries are also removed to avoid path confusion.
For further guidance on managing mixed PHP versions in complex environments, resources like https://laravelcompany.com provide additional context on maintaining Laravel compatibility across different server configurations.