WordPress is a stable platform. But one of the most common errors is “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.” This happens when your site’s PHP code is not compatible with the PHP version the site is running on.
In this guide, we will resolve the PHP error related to the missing MySQL extension in WordPress.
- Access to the server that hosts the WordPress installation (local or SSH)
- A user account with sudo privileges
- Access to a command-line/terminal window (optional)
- A package manager (like yum or apt)
Several isssues can cause the WordPress error missing mysql extension. You can resolve many of them by running an update in the WordPress admin.
To update WordPress:
- Log into the wp-admin page of your website, for example, https://examplesite.com/wp-admin/
- Click the Updates link in the upper-left corner. The page displays available updates.
- Click the Update Now button.
If your installation is up-to-date, WordPress offers an option to reinstall the current version.
WordPress is designed to disable plugins before updating. You can also manually disable any plugins first. Make sure you always update your WordPress installation before updating any plugins.
Check PHP Version on your Server
Log in to the server that hosts your WordPress site, either locally or via SSH. Check the PHP version with the command:
The system displays the version of the installed PHP software as shown below.
You can also browse the /public_html directory where your WordPress content is stored. Create a new file named info.php, then open it in an editor.
Enter the following line in the file:
<?php phpinfo(); ?>
Save the file and exit. Now you can load the file in a web browser, and the page will display a long list of all the details.
Check PHP MySQL Extension is Installed
Look through the info.php file we created in the previous section. Under the MySQL Support, find the Client API version cell check the PHP version.
Tip: Use Ctrl+F and type
MySQL Support to find this section instead of scrolling through the file.
If the Client API Version field is blank, you may be missing MySQL extensions for PHP. Enter the following commands to install them:
sudo apt-get update
sudo apt-get install php5-mysqlnd
sudo yum update
sudo yum install php-mysql
Restart the server to apply the changes.
Note: If you are running PHP7.x, replace the commands accordingly.
Check PHP Extension Configuration
If you’ve run any updates or migrated your website, there may be a mismatch in the PHP configuration in the extension_dir where WordPress looks for PHP data. On your PHP info webpage, find the Loaded Configuration File entry with the path to the php.ini file. The line may look something like this:
This is the location where your server stores PHP configuration.
Next, find the extension_dir entry in the info.php file you loaded in the browser. The line should be commented or contain a valid path to PHP extensions :
If it’s blank, edit the php.ini file:
sudo nano /opt/imh/imh-php56/root/usr/lib/php/php.ini
Scroll down to the extension_dir setting, and either update it to match your actual extension directory, or comment it out. Once you finish, save and exit, then restart your web server.
Tip: To mark a line as a comment, start the line with a semicolon
Wrong Filename or Path for MySQL.so or MySQL.dll
If you’re using a customized php.ini file, it does not always get updated when you migrate or upgrade your installation. In this case, you need to edit the php.ini file. Use a coding text editor and add the path to the file, for example:
sudo nano /opt/imh/imh-php56/root/usr/lib/php/php.ini
Find and comment the following lines:
Save the file and exit, then restart your server and test.
Missing php-mysqlnd-ms Packages (Ubuntu)
Recent versions of Ubuntu operating systems use native MySQL drivers instead of the old PHP libraries. In this case, when the php5-mysqlnd-ms package is missing, the error Your PHP installation appears to be missing the MySQL extension which is required by WordPress may appear.
Install the package by using the following command:
sudo apt-get install php5-mysqlnd-ms
When finished, restart your server and test.
Check for Other PHP Customizations
If you’ve tried all these steps and you still get the “Your PHP installation appears to be missing the MySQL extension” error, you can look at the customized configuration files.
Open your .htaccess file with a full path of your website:
sudo nano path_to_your_website/public_html/.htaccess
Go through and check the version of PHP that’s referenced. It must be the same version of PHP that you checked previously in your info.php file.
If everything looks good in .htaccess, do the same thing for your php.ini file. Again, you’re looking for references to a different PHP version than your info.php file showed.
Change the referenced version or remove that section from the file. Save the changes to the file, exit, and then restart your server.
Note: If you are using customized .htaccess and php.ini files, test your WordPress installation with default versions of these files. You can rename them
php.ini.bak to disable them. Then, either copy your backup default versions or download fresh ones.
This tutorial listed several options to fix the error “Your PHP installation appears to be missing the MySQL extension.” Typically, loading the missing MySQL extension for PHP resolves the issue.