How to fix PHP installation appears to be missing the MySQL extension?

1. PHP’s MySQL extension not installed

PHP’s ability to send SQL commands to MySQL comes from an additional module called MySQL extension. In some default operating system setup, this extension might not be present.

To check if your PHP has MySQL support, put the following code into a file called info.php in your site, and access it from a browser.


It should show a MySQL section like this:

If not, you may have to install MySQL extensions.

For Ubuntu servers, use the command:

# apt-get install php5-mysqlnd

For RedHat compatible servers, use the command:

# yum install php-mysql

2. PHP extension directory misconfigured

In some websites, especially those that were recently migrated, or in a newly setup VPS, the “extension_dir” is sometimes misconfigured.

This directory stores all the PHP libraries, and if not set correctly, PHP cannot execute those functions.

To fix this, first, locate which PHP.ini file is being loaded by your website. For this, put the following code into a file called info.php, and access it from a browser.

Look for the line called “Loaded Configuration File”. The file path noted there is the actual location to the PHP configuration file.

Now, look for the entry called “extension_dir“. It should either be commented, or it should have the correct path to PHP extensions. It should never be left blank.

If you are not sure, just comment the line, and restart the web server.

3. Wrong file name/path for or MySQL.DLL

Some websites have custom configured PHP configuration (php.ini) files. These files will not be automatically updated by system programs during an upgrade or a migration.

We’ve seen typing mistakes and wrong extension directory paths put in the custom configuration files.

If you have a custom configuration file, it is best to comment out the lines that have the following:

; extension_dir=/path/to/extensions/

4. Missing php-mysqlnd-ms packages in Ubuntu servers

In the later Ubuntu operating systems, MySQL’s native drivers are used instead of the old PHP libraries.

In these systems, if the package php5-mysqlnd-ms is not installed, it can result in this error.

So, to fix it use this command:

# apt-get install php5-mysqlnd-ms

5. Incorrect PHP config via suPHP_ConfigPath

In servers where suPHP is enabled, custom PHP configuration files are loaded through suPHP_ConfigPath.

These PHP config files sometimes contain conflicting entries on MySQL extensions. This is especially true in the case of shared servers where the Multi-PHP option is available (eg. cPanel/WHM and Plesk servers).

So, if suPHP_ConfigPath is defined in .htaccess of virtual host configuration of a website, try commenting it out to see if the error is resolved. If so, then the custom PHP.ini should be reviewed and conflicting entries should be removed.

That's it !!

Was this answer helpful? 0 Users Found This Useful (0 Votes)