WordPress Security

How to Fix the Error: “Your PHP Installation Appears to Be Missing the MySQL Extension Which Is Required by WordPress”

The “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” error message can be confusing to both beginners to WordPress and experienced users. Although it may seem like all you have to do is install the missing WordPress MySQL extension, PHP installation and configuration on the server side is much more complicated.

Avatar photo
Kiki Sheldon

The “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” error message can be confusing to both beginners to WordPress and experienced users. Although it may seem like all you have to do is install the missing WordPress MySQL extension, PHP installation and configuration on the server side is much more complicated. Moreover, there are quite a few different database drivers available for PHP, each serving the same purpose.

In this comprehensive guide to fixing the “Your PHP Installation Appears to Be Missing the MySQL Extension Which Is Required by WordPress” error, you will learn how WordPress communicates with its database and how to ensure your PHP installation has the correct MySQL extension installed for it.


How Does WordPress Communicate With Its Database?

Your WordPress website is a dynamic, database-driven web application. It essentially means two things: the vast majority of all website content is stored in the WordPress database, and WordPress absolutely relies on the ability to communicate with its database to function correctly. Each time you load any page on your website, WordPress performs a series of manipulations behind the scenes.

As all posts, pages, and other key information is stored in the database as opposed to files on the server, which we would see on a static website. WordPress PHP needs to retrieve the requested content by sending SQL queries, and merge it with template files to create an HTML page that will be sent to the website visitor. In other words, WordPress parses the address you open in the browser to form a set of query parameters, which will then be used to query the database.

So what’s the role of PHP in this process? A WordPress installation, or the WordPress core, is a set of PHP scripts that, put together, build a dynamic website. PHP as a programming language becomes the centerpiece of the WordPress architecture, which means your PHP installation must be properly configured to communicate with the WordPress database. One of the key aspects of it is having the required PHP extensions installed and enabled.

PHP MySQL Extensions for WordPress

PHP uses a special extension, or a database driver, to ensure that WordPress can establish a connection to its database using the credentials provided in the wp-config.php file. But what is this extension exactly? You may have probably seen different versions of it: mysql, mysqli, mysqlnd, pdo_mysql, libmysql, and even more. It is easy to get confused, so let’s address it once and for all.

From the 5.3 version, PHP uses the MySQL Native Driver to communicate with the database server. The MySQL Native Driver can be also referred to as mysqlnd, and is a replacement for the MySQL Client Library (libmysql) distributed by MySQL. The three MySQL extensions – mysql, mysqli, and pdo_mysql – are compiled to use the MySQL Native Driver, and are widely used with websites built on PHP.

PHP deprecated the mysql extension in the 5.5 version and removed support for it in PHP 7+ in favor of mysqli. Aligning its path with this decision, WordPress uses the mysqli extension from the 3.9 version. As pdo_mysql is not supported by WordPress, the database driver referenced in the “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” error message is the mysqli PHP extension.

Your PHP Installation Appears to Be Missing the MySQL Extension

What Does The “Your PHP Installation Appears to Be Missing the MySQL Extension Which Is Required by WordPress” Error Mean?

The “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” error means that the PHP version used by your WordPress website does not have the mysqli extension installed or configured correctly. This leads to WordPress being unable to communicate with its database, which in turn results in seeing this variation of the WordPress database connection error message on your website.

WordPress Database Connection Errors

WordPress can show database connection errors for a variety of reasons. The error message WordPress chooses to display depends on what stage it encountered issues at during a connection attempt. It is important to understand the difference between the two main errors related to its inability to communicate with the WordPress database.

The “Error establishing a database connection” message will appear on your website if the database information in the wp-config.php file is incorrect, your database user does not have sufficient privileges, your database is corrupted, or your MySQL/MariaDB server rejected the connection. In this case, WordPress can use the mysqli extension, but runs into certain issues on a later stage.

If you see the “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” error message on your website, the PHP mysqli extension is either not installed or not loaded by your PHP installation. A database driver ensures that WordPress can use its wpdb() global class, which is the first step in establishing a database connection.

3 Main Reasons Behind The WordPress MySQL Extension Missing Error

When you install WordPress for the first time or move your WordPress website to a new hosting infrastructure, you need to make sure that all services are configured correctly. It includes your web server that will accept HTTP requests, your PHP handler that will control PHP code execution, and your MySQL/MariaDB that will accept and process database requests.

Modern web hosting control panels allow you to have multiple PHP versions installed on the server at the same time. It is not the case with the traditional approach to PHP installation, when in order to use a new version of PHP, you need to remove the previous one entirely. You can also install all required PHP extensions from the graphical user interface without having to do it from the command line.

You can choose the PHP version you want to use for your WordPress website, and even a PHP handler, if you have signed up for VPS or dedicated hosting. This freedom both simplifies the process of running a website and makes it much more complicated for someone who is not familiar with the way PHP works on the server side.

Below, we are going to review the common situations that will lead to PHP being unable to communicate with your MySQL/MariaDB server. Here are the three main reasons behind the “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” error message on your website:

  • The PHP mysqli extension is missing from the PHP version used by your website.
  • The PHP mysqli extension is not configured correctly.
  • You are using an outdated version of WordPress with PHP 7+.

Reason 1: The PHP mysqli extension is missing from the PHP version used by your website

It is possible that the mysqli extension is not installed at all, especially if you have just made a new PHP version available. If WordPress can not use the mysqli extension, it will try to use the old mysql one on PHP versions lower than 7.0. The key thing is having the MySQL Native Driver installed and configured for the chosen PHP version.

How to Address

Install the MySQL Native Driver from your web hosting control panel or using the command line interface to have the WordPress mysqli extension enabled. For PHP 8.1, the package will be called php81-php-mysqlnd or ea-php81-php-mysqlnd.x86_64 if you are using cPanel.

On a CentOS server without a control panel, run yum install php81-php-mysqlnd from the command line interface. For Ubuntu servers, you apt-get to install mysqlnd. The system will automatically enable support for both mysqli and pdo_mysql.

Reason 2: The PHP mysqli extension is not configured correctly

Once the required PHP MySQL Native Driver is installed, both mysqli and pdo_mysql should be enabled and available for WordPress to use. To have the extension loaded with the PHP version you are using, a special PHP file is created in the PHP global configuration directory. If for some reason the mysqli extension can not be loaded for the chosen PHP version, WordPress will display the “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” error message.

How to Address

Verify that the MySQL Native Driver, or mysqlnd, is installed correctly, and PHP has added .ini files for both mysqlnd and mysqli. On cPanel servers, you can find the 30-mysqli.ini and 20-mysqlnd.ini configuration files in the /opt/cpanel/ea-php81/root/etc/php.d directory, where PHP 8.1 is the PHP version used by your WordPress website. The files must contain the lines below to have the extensions loaded correctly.

Reason 3: You are using an outdated version of WordPress with PHP 7+

It is unlikely, but you might still be using a very outdated version of WordPress with newer PHP versions. Not only does using outdated software versions make it much more likely to encounter various WordPress issues, it also opens up almost unlimited possibilities for hackers to gain access to your website and perform malicious actions.

How to Address

Get in the habit of keeping all software you are using updated to the latest version. Update WordPress, the active theme, and all plugins. Always use the latest PHP version to avoid any issues that stem from code incompatibility and unpatched security vulnerabilities.

As you do not have access to the WordPress admin dashboard, use the WordPress Command Line Interface to perform all updates. You can use the following commands:

  • wp core update. Update WordPress core.
  • wp plugin update <plugin name>. Update a certain plugin or use the —all flag to update all plugins at once.
  • wp theme update <active theme name>. Update your active theme.

If WordPress shows you the missing MySQL extension error message, it’s a sign to take your WordPress website more seriously. Take a proactive approach to managing all aspects of it, especially when it comes to security. iThemes Security Pro and BackupBuddy, the industry-leading solutions for WordPress security and data protection, can make the process easy and headache free.

Using iThemes Security Pro is like having a security expert on your team that will monitor your WordPress website 24/7, allowing you to focus on growing your business. Protecting over a million WordPress sites worldwide, BackupBuddy automatically backs up your website at regular intervals to store a copy of it in a secure location for one-click restores whenever you need them. This way, you can easily recover from all WordPress errors and malware infections, but remember – attack prevention is always better than dealing with consequences.

The Site Scan feature checks the critical areas of your website and automatically applies fixes to keep your website free of outdated plugins and themes that put it at a great risk. With iThemes Security Site Scan, you can significantly reduce the attack surface and keep your website secure from network attacks of all kinds.

iThemes Security Version Management allows you to configure auto updates for WordPress core, plugins, and themes to leverage new features and stay protected from known vulnerabilities.
Keeping WordPress up to date is extremely important and can save you tons of time dealing with various WordPress issues caused by outdated software.

Other reasons

Just like any other WordPress issue, the error“Your PHP installation appears to be missing the MySQL extension which is required by WordPress” can be displayed on your website for a wide variety of reasons that go beyond what we outline above. However, most of the time they are related to PHP handlers misconfigurations or using the CloudLinux operating system which has its own way of configuring PHP on the server side.

CloudLinux PHP Selector

Using Cloudlinux, you can leverage CageFS, a robust solution for total user isolation, which prevents cross-account symlink attacks and secures your websites. If you are using CageFS, you need to use the CloudLinux PHP Selector, which often introduces additional complications for cPanel users who would normally manage server-side PHP from the MultiPHP Manager. Refer to the CloudLinux guide to using PHP Selector with cPanel or contact your hosting provider for assistance.

How To Fix The “Your PHP Installation Appears to Be Missing the MySQL Extension Which Is Required by WordPress” Error

To fix the error “Your PHP installation appears to be missing the MySQL extension which is required by WordPress”, you will need to make sure that your PHP installation has the MySQL Database Driver (mysqlnd) and the mysqli extension installed and configured correctly. Only then you will be able to restore normal connection between WordPress and the WordPress database and get your website working again.

Follow the steps below to fix the WordPress MySQL missing extension error:

  • Create a PHP information page to review your PHP configuration.
  • Verify that the mysqli extension is installed and configured correctly.
  • Restore the WordPress’ ability to connect to its database and prevent future errors.

Step 1. Create a PHP information page to review your PHP configuration

The easiest way to check your PHP installation configuration is by creating a PHP info page. Create a file named phpinfo.php in your WordPress website’s document root directory and insert the following code into it:

<?php
phpinfo( );
?>

Alternatively, run the following if you are logged in to your website via SSH. It will create a phpinfo.php file and adjust its permissions.

echo "<?php phpinfo(); ?>" > phpinfo.php ; chown $(stat -c %U .). phpinfo.php

Open the newly created phpinfo.php page in the browser by typing yourwebsite.com/phpinfo.php in the address bar. Replace yourwebsite.com with the actual domain name of your WordPress website. Even if no content loads due to the missing MySQL extension error, you will not have any issues opening the PHP information page.

You should see a page similar to the one below, which will contain all configuration for the PHP version you are using for your WordPress website. In this case, it is PHP 8.1. Having a PHP information page is useful for troubleshooting various WordPress errors, including the “There Has Been a Critical Error on Your Website” message in WordPress.

At the top of the page, you will see the PHP version used by your WordPress website. Here are some of the most important aspects of your PHP installation that you should check first:

  • PHP handler. The PHP handler used by your website will be displayed as the Server API. In the screenshot above, it is FPM/FastCGI.
  • Loaded configuration file. The main configuration file loaded for the PHP version in use.
  • Additional .ini files parsed. This list will contain all other PHP configuration files loaded, including the ones loading the MySQL Native Driver (20-mysqlnd.ini), and the mysqli extension (30-mysqli.ini).

Make sure the list of additional .ini files parsed contains the required 20-mysqlnd.ini and 30-mysqli.ini files that make sure the required PHP WordPress MySQL extension mysqli is loaded correctly and can be used by your website.

Step 2. Verify that the mysqli extension is installed and configured correctly

Scroll down the PHP information page or use the search option in the browser to review the mysqli and mysqlnd sections of it. They should go one after the other.

Note that the mysqli extension is compiled to use the MySQL Native Driver as the Client API Library version shows us mysqlnd. The PHP extension information shows us some additional details, including the MySQL/MariaDB port.

Check what API Extensions the mysqlnd section of the PHP information file lists. In the screenshot above, we have both mysqli and pdo_mysql enabled.

Step 3. Restore the WordPress’ ability to connect to its database

The PHP information page will show you whether the PHP version you use for your WordPress website has the mysqli extension installed and configured. If it is missing, install it from the PHP management interface provided by your web hosting control panel or using the command line interface.

Check the 20-mysqlnd.ini and 30-mysqli.ini referenced to see if they load the extension correctly. If you are using an outdated version of WordPress, update the installation and all plugins and themes.

The steps we outlined in this guide should help you restore the functionality of your WordPress website in the vast majority of cases. However, as we mentioned, there can be other issues, including PHP handler misconfigurations, that can lead to seeing the “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” error message on your website. It is best to contact your web hosting support team for further assistance if it is not clear what is causing the issue.

Wrapping Up

The WordPress MySQL missing extension error is one of the WordPress issues related to its ability to communicate with its database. It indicates that the required PHP mysqli extension is either missing or configured incorrectly, which results in PHP being unable to send SQL queries to your WordPress database. Starting from PHP 7.0, the older mysql extension was removed in favor of mysqli, the new WordPress MySQL extension compiled to use the MySQL Native Driver.

Just like any other critical WordPress error, seeing the error “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” means that you need to review your WordPress configuration and ensure the best security practices are in place.

Taking a proactive approach to WordPress website administration and security will help you prevent most errors and reduce the attack surface significantly. Configure monitoring, automatic software updates, and regular backups to have your website protected from security vulnerabilities and network attacks Let iThemes Security Pro and BackupBuddy be your team of security and data recovery experts that will make sure your website never goes offline.

Solid Security is part of Solid Suite — The best foundation for WordPress websites.

Every WordPress site needs security, backups, and management tools. That’s Solid Suite — an integrated bundle of three plugins: Solid Security, Solid Backups, and Solid Central. You also get access to Solid Academy’s learning resources for WordPress professionals. Build your next WordPress website on a solid foundation with Solid Suite!

Get Solid Security

Did you like this article? Spread the word: