Enabling MySQL Native Driver for PHP on RPM-based Systems
You are attempting to migrate from the legacy libmysql client library to mysqlnd, but your system is presenting a classic packaging conflict. The error message you encounteredâphp-mysql conflicts with php-mysqlndâis not a bug; it is a deliberate safeguard built into the RPM package management system used by CentOS, Amazon Linux, and other distributions based on these packages.
The core issue lies in the architecture of PHP extensions themselves. Unlike some languages where you can simply drop a new library file onto your system, PHP extensions (.so files) are compiled against specific libraries at build time. The standard php-mysql package provides an extension that links directly to the older MySQL C client API. In contrast, the php-mysqlnd package provides an extension linked against the MySQL Native Driver (mysqlnd).
When you run the command yum install php-mysqlnd, the dependency resolver sees two packages defining the same namespace: php-pdo_mysql.so. Because both extensions aim to provide PDO support for MySQL, but they link to different underlying libraries, they cannot coexist in a standard RPM environment. The conflict prevents the installation because the system does not know which library implementation to use at runtime without manual intervention or breaking changes.
Why You Can't Just Compile It In-Place
The source material suggests updating the ./configure flags with --with-mysql=mysqlnd. This approach works perfectly for a fresh, custom build of PHP from source code. If you are compiling PHP in your home directory or on a server without pre-existing packages, this is indeed the correct path. You ensure that every extension builtâstandard MySQLi, PDO MySQL, and potentially the standalone mysqlnd clientâis compiled against the native driver headers.
However, if you are running a production environment with php-mysql already installed via your package manager, simply recompiling PHP or copying the compiled .so file is often insufficient. The RPM database maintains strict records of installed files and libraries. If you compile a new extension that links to different system libraries, you risk creating a state where the running PHP binary expects one set of symbols while the shared library provides another, leading to runtime errors.
Resolving the Conflict on Amazon Linux 1
The error log explicitly references amzn1, indicating this scenario is common on Amazon Linux 1, which ships with PHP 5.3.17. On these specific systems, the default package manager does not offer a neutral ground between the two implementations. You face a binary choice: stick with the legacy driver or switch to mysqlnd.
To enable mysqlnd successfully on an RPM-based system, you must explicitly remove the conflicting package before installing the new one. This ensures that only one implementation of the PDO MySQL extension is present in the filesystem.
# Remove the legacy mysql driver package
yum remove php-mysql
# Install the native driver package
yum install php-mysqlnd
Once installed, you must verify that the configuration file has been updated to reference the new extension. In many cases, the package manager will automatically update the php.ini file, but it is prudent to check the active configuration:
grep -i "pdo_mysql" /etc/php.ini
You should see a line similar to:
extension=pdo_mysql.so
Ensure that there are no duplicate lines or references to a legacy mysql extension. If you find multiple entries, remove the duplicates to prevent PHP from loading conflicting symbol tables.
Performance and Compatibility Considerations
Switching to mysqlnd is generally recommended for performance and stability. The native driver is written in C and optimized specifically for the PHP runtime environment, whereas the legacy library relies on generic C bindings that can introduce overhead. Furthermore, mysqlnd includes a built-in compression layer (optional) that reduces network traffic between your application and the database server.
However, be aware of version-specific limitations. The source material notes PHP 5.3.17, which is an end-of-life version. While mysqlnd works with this version, newer versions of MySQL or MariaDB might introduce features that require a more recent PHP build to fully utilize. If you are maintaining legacy applications, ensure your database client driver supports the specific protocol version required by your database server.
Final Verification
After resolving the package conflict and updating the configuration, restart your web server (Apache, Nginx with PHP-FPM, etc.) to clear any cached extension states:
service httpd restart
# or
systemctl reload php-fpm
Reload your application and run phpinfo(). If you see the section titled "MySQLnd" in the output, confirming that the driver is active, and the "Client library" field displays mysqlnd, the migration is successful. You have replaced the legacy library with the native implementation without breaking your PHP installation.