Skip to content

How to fix "Your PHP installation appears to be missing the MySQL extension" in WordPress

The PHP that runs the site has no mysqli extension loaded, so WordPress cannot reach its database and stops before it does anything else. Nothing is lost. Switch mysqli on for the PHP version the site really runs, in the hosting panel or through the host.

By
WP Ministry
Published
Tested on
WordPress 7.1.3, PHP 8.3.35

In short

  • Nothing is lost. WordPress stopped before it opened the database or changed a file.
  • WordPress tests for one thing, PHP's mysqli extension. mysqlnd in a list of modules is the driver under it and does not count.
  • Look at what changed in PHP. A version chosen in the hosting panel has its own list of extensions, and mysqli may be off in it.
  • The panel shows what was asked for. A five-line file in the site's folder shows what the site really runs.
  • The command line can run a different PHP from the website, so WP-CLI can print the message while the site works, and the other way round.
  • A WordPress older than 3.9 prints it on every PHP from 7.0 on, whatever is loaded.

WordPress prints this when the PHP that is running it has no mysqli extension loaded. mysqli is the part of PHP that talks to a MySQL or MariaDB database. WordPress checks for it before it does anything else, and without it there is no way to reach the database, so it stops and says so.

Nothing is lost. WordPress stopped before it opened the database or changed a file. The site comes back as soon as the PHP behind it has mysqli again.

The fault is in how PHP is set up on the server. Ask what changed there: a new PHP version chosen in the hosting panel, a move to another server, an upgrade of the server's software. It is a different fault from "Error establishing a database connection", where PHP has the extension and the database does not answer.

What you see

Since WordPress 6.2 the message is a plain page titled "Requirements Not Met", with three paragraphs:

text
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Please check that the mysqli PHP extension is installed and enabled.

If you are unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress support forums.

It shows on every address of the site: the front page, the login page, the dashboard, the REST API. The server sends it with status 500.

WordPress 5.3 to 6.1 shows the first sentence alone on the same kind of page. Older versions print that sentence as a bare line of text. WP-CLI prints all three after the word "Error:".

What WordPress tests for

The sentence has not changed since WordPress 3.0. What it tests has.

WordPressWhat it looks for
6.4 and laterthe function mysqli_connect(), which the mysqli extension provides
6.2 and 6.3mysqli_connect() or mysql_connect()
4.5 to 6.1any of three extensions: mysql, mysqli or mysqlnd
3.9 to 4.4mysql or mysqli
3.8 and oldermysql and nothing else

Three things follow from the table.

  • On any PHP from 7.0 on, mysqli is the one that counts. The old mysql extension was deprecated in PHP 5.5 and removed in PHP 7.0, and mysql_connect() went with it.
  • mysqlnd in a list of loaded modules is not enough. It is the driver that mysqli is built on. PHP's manual says it "does not provide a new API to the PHP programmer", and WordPress's hosting handbook says "mysqlnd is not a standalone replacement for mysqli". A PHP can have the driver loaded and mysqli missing.
  • WordPress 4.5 to 6.1 can fail with a different message for the same cause. On a PHP with the driver and no mysqli, those versions pass the test, go on to connect, and stop with the fatal error Call to undefined function mysql_connect(). If that line is in your error log, the fixes on this page apply. "There has been a critical error on this website" shows where to read the log.

WordPress skips the test when a database drop-in, wp-content/db.php, is present.

Where it goes wrong

A page request passes through each of these in turn. This one comes from PHP, the language WordPress runs on.

  1. Browser
  2. DNS
  3. HTTPS
  4. CDN or firewall
  5. Web server
  6. PHP (this error comes from here)
  7. WordPress
  8. Database and files

What causes it

How to fix it

See what the PHP behind the site has loaded

  • Easy
  • No risk
  • About 10 minutes
  • Steps tested on WordPress 7.1.3

The hosting panel shows what it was asked to set up. This shows what the site really runs, and it tells you which of the other fixes you need.

  1. Step 1: Make a file named mysqli-check.php

    Put it in the folder WordPress is installed in, beside wp-config.php. Use your host's file manager, or connect over SFTP. This is the whole file:

    mysqli-check.php
    <?php
    header( 'Content-Type: text/plain; charset=utf-8' );
    echo 'PHP version: ', PHP_VERSION, "\n";
    echo 'Runs as: ', PHP_SAPI, "\n";
    echo 'mysqli: ', function_exists( 'mysqli_connect' ) ? 'loaded' : 'missing', "\n";
    echo 'php.ini: ', php_ini_loaded_file() ?: 'none', "\n";
    echo 'Extension folder: ', ini_get( 'extension_dir' ), "\n";
  2. Step 2: Open it in your browser

    Its address is your site's address followed by /mysqli-check.php, for example https://example.com/mysqli-check.php. It runs without WordPress, so it works while the site is down. On a server where nothing is wrong it prints five lines like these:

    text
    PHP version: 8.3.35
    Runs as: apache2handler
    mysqli: loaded
    php.ini: none
    Extension folder: /usr/local/lib/php/extensions/no-debug-non-zts-20230831
  3. Step 3: Read the five lines

    • mysqli says missing when the message is right. It asks PHP the same question WordPress 6.4 and later asks. If it says loaded and the site still shows the message, WordPress is older than 3.9: go to the last fix.
    • PHP version is the version this folder really runs. If it is not the one your hosting panel shows, something is holding the site on another version: go to "Remove what keeps the site on another PHP version".
    • php.ini is the main configuration file PHP read. A path inside your own account, such as your home folder or the site's folder, means a file of yours has replaced the server's: go to "Take a leftover php.ini out of the way".
    • Extension folder is where PHP looks for mysqli. If the path names a PHP version, it should be the version on the first line. A different one means PHP is looking among another version's extensions.
    • Runs as says how the web server starts PHP. apache2handler is PHP inside Apache, which reads its configuration once, when the web server starts. cgi-fcgi is PHP's CGI program. fpm-fcgi and litespeed are two more names you may see.
  4. Step 4: Delete the file

    It tells anyone who opens it how the server is set up. Delete it as soon as you have read it, in the file manager or over SSH from the WordPress folder:

    bash
    rm mysqli-check.php

Over SSH, three commands answer the same questions for the command line. The first prints mysqli when the extension is loaded and nothing when it is not. Search for mysqli, not mysql: the driver's name, mysqlnd, contains "mysql" too.

bash
php -m | grep -i mysqli

The second lists the php.ini in use and every additional .ini file PHP read. Where extensions are installed as packages, one of those small files is what loads mysqli.

bash
php --ini

The third is WP-CLI's own report. Read the lines "PHP binary" and "php.ini used".

bash
wp --info

To undo it: Delete mysqli-check.php from the server.

Switch mysqli on for the PHP version the site runs

  • Easy
  • Low risk
  • About 10 minutes

A server keeps a set of extensions for each PHP version. The version you have just moved to may not have what the old one had.

  1. Step 1: Open the PHP settings in your hosting panel

    The name differs from host to host. On hosts that use CloudLinux's PHP Selector with cPanel it is Select PHP Version, in the Software section. Its documentation describes a "PHP Extensions" page where "you can choose extensions for the particular PHP version".

    cPanel's own MultiPHP Manager sets the PHP version for a domain, and its documentation describes no list of extensions. On those servers an extension is a package that the server's administrator installs.

  2. Step 2: Check the version first

    Make sure the panel shows the version you meant to choose, and that it matches the "PHP version" line of the check file.

  3. Step 3: Tick mysqli

    In the list of extensions, tick mysqli. CloudLinux's list can also have nd_mysqli: its documentation says that for a PHP version that has it, its installer switches nd_mysqli on and mysqli off unless the server's owner has set other defaults. Tick nd_mysqli if the list has it, otherwise mysqli. Save if the panel has a save button. In PHP Selector, changes are saved as you make them.

  4. Step 4: Reload the site

    If the message is still there, open the check file again. Once it says loaded, WordPress gets past this check.

  5. Step 5: If there is no such list, write to the host

    Send the exact message, the PHP version from the check file, and when it began. Ask them to enable the mysqli extension for that PHP version on your account. WordPress hosting problems: how to tell whether the fault is the host or the site has a message you can copy and adapt.

  6. Step 6: Meanwhile, set the PHP version back

    If the site worked on the previous version, choosing it again brings the site back while you wait. Treat that as temporary if the old version is past its end of life. The WordPress and PHP end-of-life checker shows which versions still get security fixes.

To undo it: Set the PHP version back to the one the site ran on, or clear the box you ticked.

Take a leftover php.ini out of the way

  • Takes care
  • Low risk
  • About 10 minutes
  • Steps tested on WordPress 7.1.3

PHP looks for its main configuration file in a list of places, in order, and uses the first one it finds. Ahead of the server's own place, the list has the folder named in an environment variable, PHPRC, and, except on the command line, the folder PHP is working in. A php.ini found in either is used in place of the server's. Hosting panels write such files: cPanel's MultiPHP INI Editor saves a php.ini in a domain's folder or in the home directory.

A file like that outlives the PHP version it was written for. If it sets extension_dir to the old version's folder, the new PHP looks there for mysqli and cannot load it. The server's error log then has a line that starts like this, followed by the folder it tried:

text
PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli'
  1. Step 1: Find the file

    The "php.ini" line of the check file names the one in use. Otherwise look for a file named php.ini in the WordPress folder and in your account's home folder.

  2. Step 2: See what it says about extensions

    Open it and search for the word "extension". Over SSH, from the folder the file is in:

    An extension_dir line with a path that belongs to another PHP version is the fault. So are extension= lines that name files the new version does not have.

    If the check file names this file as the php.ini in use, go on to rename it even when the search prints nothing. CloudLinux's documentation notes that beside a custom php.ini the server's additional .ini files may not be loaded, and those are what load the extensions.

    bash
    grep -n -i "extension" php.ini
  3. Step 3: Rename it

    Renaming keeps the file, so you can read your old settings from it later.

    PHP no longer finds a php.ini there and goes back to the server's own. cPanel's documentation gives the same advice for its editor: to reset PHP's settings to their defaults, delete the domain's or the home directory's php.ini file.

    bash
    mv php.ini php.ini.off
  4. Step 4: Reload the site

    PHP's CGI program reads its configuration each time it is started, so the change shows on the next request or soon after. Where PHP stays running between requests, it shows when PHP is next restarted. Your panel may have a button for that, or the host can do it.

  5. Step 5: Set again what you still need

    The old file may also have raised the memory limit or the upload size. Set those again in the panel's PHP options, for the version you are on now.

Leave .user.ini alone. PHP reads only some settings from that file, and neither extension nor extension_dir is among them, so it cannot cause this message.

To undo it: Rename php.ini.off back to php.ini.

Remove what keeps the site on another PHP version

  • Takes care
  • Back up first
  • About 15 minutes

Use this when the check file shows a PHP version that is not the one in your hosting panel. You switched mysqli on for one version, and the site runs another.

Some panels write the choice of PHP version into .htaccess. cPanel's documentation says that when you set a domain's PHP version the system creates its .htaccess file, and that a domain set to inherit takes its version from the first .htaccess with PHP version information that Apache finds on the way up through the folders. A line left in the site's folder, or in a folder above it, can therefore decide the version.

  1. Step 1: Download a copy of .htaccess

    It is in the WordPress folder. It may be hidden: turn on "show hidden files" in the file manager.

  2. Step 2: Set the PHP version again in the panel

    Choose the version you want and apply it, even if the panel already shows it. That makes the panel write its own lines again. cPanel recommends setting the version only through its interface, and warns that a version set by hand may behave unexpectedly.

  3. Step 3: Look for lines the panel did not write

    In .htaccess in the WordPress folder and in each folder above it, look for lines that name a PHP version or a path to a php.ini: lines that begin AddHandler or SetHandler and mention PHP, and lines with suPHP_ConfigPath, PHPRC or lsapi_phprc. CloudLinux's documentation tells server owners not to redefine the path to php.ini with settings such as SuPHP_ConfigPath and PHPRC, because doing so can break its PHP Selector.

  4. Step 4: Remove a line that points at the old version, and reload

    Remove one line at a time and reload the site after each. If the site answers with a server error, put the line back from your copy.

  5. Step 5: Run the check file again

    The "PHP version" line should now match the panel.

To undo it: Upload the copy of .htaccess you downloaded.

On your own server, install mysqli and restart PHP

  • Advanced
  • Low risk
  • About 15 minutes

This is for a server you administer yourself. On shared hosting, use the hosting panel fix above.

  1. Step 1: Install the package for the PHP version the site runs

    PHP's manual says that on Linux the MySQL extensions "may need to be installed using an additional package", and to look in the distribution's package manager. On Ubuntu:

    That package is for the distribution's default PHP. Where a server has more than one PHP version, each has a package of its own with the version in its name, such as php8.3-mysql. Install the one that matches the "PHP version" line of the check file. On Fedora the package is php-mysqlnd. On a cPanel server the administrator installs PHP extensions in WHM's EasyApache 4 interface.

    bash
    sudo apt install php-mysql
  2. Step 2: Or switch it on in php.ini

    Where PHP was installed without a package manager, as on Windows, the extension is a line in php.ini. The file PHP ships with has it commented out with a semicolon, as ;extension=mysqli. Remove the semicolon so the line reads:

    php --ini shows which php.ini the command line reads. The check file shows which one the website reads.

    php.ini
    extension=mysqli
  3. Step 3: Restart the web server

    PHP inside a web server reads its configuration once, when the web server starts. Until a restart, nothing changes. On Ubuntu with Apache:

    If the site uses PHP-FPM, restart that service too.

    bash
    sudo systemctl restart apache2.service
  4. Step 4: Run the check file again

    It should now say mysqli: loaded.

To undo it: Remove the package with the same package manager, or put the semicolon back, and restart the web server again.

Run WP-CLI with the PHP the site uses

  • Takes care
  • No risk
  • About 10 minutes

Use this when the site loads and only WP-CLI, or a scheduled command, prints the message.

  1. Step 1: See which PHP WP-CLI found

    Run wp --info and read the "PHP binary" line. That is the program WP-CLI started with, usually the first php in your shell's search path.

  2. Step 2: Find the PHP the website uses

    The check file gives its version. Your host's documentation, or the host, can give the path of the command-line program for that version. A server with several versions keeps each in a folder of its own: CloudLinux's documentation shows paths such as /opt/alt/php72/usr/bin/php.

  3. Step 3: Run WP-CLI with that PHP

    Put the path of that PHP before the path of WP-CLI's file. which wp prints the second.

    "PHP binary" should now be the one you named. Use the same form for any other command, and in a scheduled command, where the search path can differ from your shell's.

    bash
    /path/to/php /path/to/wp --info
  4. Step 4: Make it the default

    WP-CLI's handbook says to put the folder of the PHP you want first in your PATH, in your shell's profile. Its WP_CLI_PHP setting works only when WP-CLI was not installed as a Phar file, and the Phar is the install its handbook recommends.

If the command line's PHP is the right version and simply lacks mysqli, ask the host to enable the extension for the command line as well, or on your own server install the package for that version. How to use WP-CLI to manage a WordPress site covers connecting and checking the install.

To undo it: Nothing on the site is changed. Take the line out of your shell profile if you added one.

Bring a WordPress older than 3.9 up to date

  • Advanced
  • Back up first
  • About 60 minutes

To see which WordPress the site runs, open wp-includes/version.php and read the line that begins $wp_version.

WordPress 3.8 and older asks PHP for the mysql extension by name and for nothing else. PHP removed that extension in 7.0. On any PHP since, such a WordPress prints the message whatever is loaded, and no extension setting changes that. It cannot run its own updater either, because it stops before the dashboard loads.

  1. Step 1: If the host still offers the PHP the site last ran on

    Set the PHP version back. The site loads again, and you have the dashboard to back up and update from. Treat it as a stopgap. A PHP from before 7.0 is years past its end of life, and current WordPress needs PHP 7.4 or later, so the site has to move forward in the end. The WordPress and PHP end-of-life checker shows where each version stands.

  2. Step 2: Otherwise, replace WordPress's files by hand

    WordPress's documentation calls this a manual update. Download the current WordPress. On the server, delete the old wp-includes and wp-admin folders and upload the new ones. Upload the new files from the top folder over the old ones. Keep wp-config.php and the wp-content folder as they are.

  3. Step 3: Update the database

    Open /wp-admin on your site. WordPress sees that the database is older than the files and gives you a link to wp-admin/upgrade.php. Follow it.

  4. Step 4: Expect the theme and plugins to need work

    Code from the same years as that WordPress may stop on a current PHP. If the site then shows "There has been a critical error on this website", that page shows how to find the plugin or theme and switch it off from outside.

How to safely update WordPress, plugins and themes covers backing up and updating one thing at a time once the site is running.

To undo it: Restore the files and the database from the backup you took before you began.

When to get help

Stop when the panel has no setting for extensions and the host will not switch mysqli on, when the check file says mysqli is loaded and the message is still there, or when the site runs a WordPress from before 3.9 that has to be brought forward many years in one step. Each needs access to the server and a backup taken first. On a store, stop sooner. No order can be placed while the message shows.

Common questions

Is my content gone?

No. WordPress made this check before it connected to the database, and it wrote nothing. Posts, pages, users, settings and uploads are as they were.

The module list shows mysqlnd, or pdo_mysql. Why does WordPress still say MySQL is missing?

WordPress tests for the function mysqli_connect(), which only the mysqli extension provides. mysqlnd is the driver under it and pdo_mysql is a different extension. Neither one gives WordPress what it asks for.

Why does WP-CLI print the message when the site works?

The command line is running a different PHP program from the website, or the same one with a different configuration, and that one has no mysqli. wp --info shows which PHP and which php.ini WP-CLI used.

Can I fix it from wp-config.php, .htaccess or a plugin?

No. PHP loads extensions only when it starts, from php.ini: its manual marks the extension setting as changeable in "php.ini only". WordPress runs this check before it loads any plugin. The change has to be made where PHP is configured, which on shared hosting means the panel or the host.

Is this the same as "Error establishing a database connection"?

No. That message means PHP has mysqli and the connection failed: the details in wp-config.php are wrong or the database server is not answering. How to fix "Error establishing a database connection" covers it.

More on this subject

Would you rather we fixed it?

Quick Fix is $49. One issue, one site, up to about an hour. No fix, no fee. 30-day warranty. It starts with a free diagnosis.