Fixing the 'Missing MySQL Extension' Error in WordPress

intermediate📝 WordPress2026-05-29| PHP 7.0+, WordPress 4.0+, Linux (Ubuntu/Debian, CentOS), Docker

Error Message

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
#wordpress#php#mysql#devops

The ContextSeeing this error usually means one thing: your PHP environment can't talk to your MySQL database. It's a classic symptom of a PHP version jump—say, moving from PHP 7.4 to 8.3—or a fresh server setup.

The error message itself is a bit of a relic. While it mentions the 'MySQL extension,' modern WordPress actually relies on mysqli or pdo_mysql. Since the original mysql driver was scrapped back in PHP 7.0, this generic message is just WordPress's way of saying it can't find a compatible bridge to your data.

The Debug ProcessDon't start changing configs blindly. First, verify if the extension is actually missing from your PHP runtime by running this in your terminal:

php -m | grep -i mysql

If you get a blank line, the extension is missing from your CLI environment. However, a common trap is assuming the terminal speaks for the web server. PHP-FPM (web) and PHP-CLI often use different configurations. To see what your browser sees, drop a file named info.php into your WordPress root:

<?php phpinfo(); ?>

Open yourdomain.com/info.php and search for "mysqli" or "mysqlnd". If those sections are missing, the extension is inactive or uninstalled.

Solutions### 1. Install the Extension on LinuxOn most Linux distros, the MySQL extension is a separate package. You need to match the package to your specific PHP version exactly.

Ubuntu / Debian```

Find your active version first

php -v

If you're on PHP 8.1, run:

sudo apt update sudo apt install php8.1-mysql

Then restart your service

sudo systemctl restart apache2

For Nginx users:

sudo systemctl restart php8.1-fpm


#### CentOS / RHEL / Fedora```
# Modern RHEL-based systems use dnf
sudo dnf install php-mysqlnd
sudo systemctl restart httpd
# For Nginx/PHP-FPM setups:
sudo systemctl restart php-fpm

2. Flip the Switch in php.iniSometimes the software is there, but the "on" switch is flipped off in your configuration file.

  • Find your php.ini path (look for "Loaded Configuration File" in your phpinfo() output).- Search for the line ;extension=mysqli.- Remove the semicolon (;) to enable it:``` extension=mysqli extension=pdo_mysql

Save the file and restart Apache or PHP-FPM to apply the changes.
### 3. Fix for Docker EnvironmentsIf you're running the official PHP Docker image, `apt-get install` won't work for PHP extensions. You must use the `docker-php-ext-install` helper in your Dockerfile to compile them correctly:

FROM php:8.2-fpm RUN docker-php-ext-install mysqli pdo_mysql

Rebuild your image after saving


If you're using Docker Compose, check your database environment variables. Sometimes a failed connection in older WordPress versions triggers this misleading "missing extension" error instead of a connection timeout.
### 4. Windows (WAMP/XAMPP)For local developers using XAMPP, open the Control Panel and click 'Config' next to Apache to open `php.ini`. Ensure `extension=mysqli` isn't commented out. Also, double-check that your `extension_dir` points to the actual `ext` folder path—usually something like `"C:\xampp\php\ext"`.
## Verification StepsSuccess looks like this:
- **On the Command Line:** Run `php -m | grep mysqli`. The word `mysqli` should pop up immediately.- **On the Web:** Refresh your `info.php` page. You should see a dedicated "mysqli" header listing the Client API library version.- **In WordPress:** Your site should load normally. If you see "Error establishing a database connection" instead, you've fixed the extension but have the wrong DB credentials.## Key Takeaways- **CLI vs Web:** Never assume `php -m` in the terminal proves the web server is working. They often use different `php.ini` files.- **Go Native:** Always prefer `mysqlnd` (MySQL Native Driver). It's faster and uses significantly less memory than the old `libmysqlclient`.- **Cleanup:** Security is paramount. Delete that `info.php` file as soon as you're done, as it's a goldmine for attackers.

Related Error Notes