Back to Troubleshooting

WordPress Missing MySQL Extension Error | NOC.org Support

The error "Your PHP installation appears to be missing the MySQL extension which is required by WordPress" appears when WordPress cannot find a PHP module for connecting to MySQL. This is one of the most common errors after installing PHP, upgrading PHP versions, or setting up a new server. The fix is straightforward: install the correct PHP MySQL extension for your PHP version.

Understanding the MySQL Extensions

PHP has had several MySQL extensions over the years. Understanding which is which helps you install the right one:

mysql (ext/mysql) — Removed in PHP 7.0

The original mysql_* functions (mysql_connect(), mysql_query(), etc.). This extension was deprecated in PHP 5.5 and completely removed in PHP 7.0. If you are running PHP 7.0 or later, this extension does not exist and cannot be installed.

mysqli (ext/mysqli) — Recommended

The "MySQL Improved" extension. It provides both a procedural and object-oriented interface, supports prepared statements, multiple statements, and transactions. WordPress has used mysqli as its primary database driver since WordPress 3.9 (2014).

mysqlnd (MySQL Native Driver)

mysqlnd is not a standalone extension but a replacement driver that mysqli and PDO_MySQL use under the hood. It is written in PHP internals and does not require the MySQL client library (libmysqlclient). Most modern PHP packages use mysqlnd by default.

Why This Error Occurs

  • Fresh PHP installation without the MySQL module: On many Linux distributions, PHP is installed as a minimal package. MySQL support is a separate package that must be installed explicitly.
  • PHP version upgrade: Upgrading from PHP 7.x to 8.x installs the new PHP version but does not automatically install the MySQL extension for it. You had php7.4-mysql installed, but now you need php8.2-mysql.
  • Multiple PHP versions: The server has several PHP versions installed. The web server is using a PHP version that does not have the MySQL extension, even though another version does.
  • Very old WordPress on PHP 7.0+: If running a WordPress version older than 3.9 on PHP 7.0+, WordPress may still try to use the removed mysql_* functions. The solution is to update WordPress.

Checking Installed PHP Extensions

# List all installed PHP modules:
php -m

# Check specifically for MySQL-related modules:
php -m | grep -i mysql

# Expected output on a properly configured system:
# mysqli
# mysqlnd
# pdo_mysql

# Check via PHP info:
php -i | grep -i "mysql"

# Check which php.ini is loaded:
php --ini

If mysqli does not appear in the output, the extension is not installed.

Installing the MySQL Extension

Ubuntu / Debian

# For PHP 8.2:
sudo apt update
sudo apt install php8.2-mysql

# For PHP 8.1:
sudo apt install php8.1-mysql

# For PHP 8.0:
sudo apt install php8.0-mysql

# For PHP 7.4:
sudo apt install php7.4-mysql

# The php-mysql package installs for the default PHP version:
sudo apt install php-mysql

The php8.2-mysql package installs both the mysqli and pdo_mysql extensions compiled against the mysqlnd driver.

CentOS / RHEL / AlmaLinux / Rocky Linux

# For PHP from default repos:
sudo yum install php-mysqlnd
# or
sudo dnf install php-mysqlnd

# For PHP from Remi repository (specific version):
sudo dnf install php82-php-mysqlnd
# or
sudo dnf install php81-php-mysqlnd

Amazon Linux 2

# With amazon-linux-extras:
sudo amazon-linux-extras install php8.2
sudo yum install php-mysqlnd

Restarting the Web Server

After installing the extension, you must restart PHP-FPM or Apache for the change to take effect:

# If using PHP-FPM:
sudo systemctl restart php8.2-fpm

# If using Apache with mod_php:
sudo systemctl restart apache2

# If using Nginx (restart PHP-FPM, not Nginx):
sudo systemctl restart php8.2-fpm

Verifying the Installation

After installing and restarting, verify the extension is loaded:

# From the command line:
php -m | grep -i mysql

# Expected output:
# mysqli
# mysqlnd
# pdo_mysql

You can also create a temporary phpinfo() file to check from the web server:

# Create a test file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

# Visit http://yourdomain.com/phpinfo.php in a browser
# Search for "mysqli" on the page — you should see a section with configuration details

# IMPORTANT: Delete this file when done (it exposes sensitive server information):
sudo rm /var/www/html/phpinfo.php

Multiple PHP Versions: Finding the Right One

If you have multiple PHP versions installed, make sure you are installing the extension for the version your web server uses:

# Check which PHP version the CLI uses:
php -v

# Check which PHP version PHP-FPM uses:
# Look at which PHP-FPM service is running:
systemctl list-units | grep php-fpm

# Check which PHP version Apache uses:
# Look at the loaded modules:
apache2ctl -M | grep php

# Or check the socket/handler in your Apache/Nginx config:
grep -r "php.*fpm\|php.*sock" /etc/apache2/sites-enabled/
grep -r "php.*fpm\|php.*sock" /etc/nginx/sites-enabled/

The CLI PHP version and the web server PHP version can be different. Install the MySQL extension for whichever version the web server is using.

PHP 7.0+ Removed Legacy mysql_* Functions

If you are seeing this error on PHP 7.0 or later, be aware that:

  • The old mysql_connect(), mysql_query(), and related functions no longer exist in PHP 7.0+.
  • You cannot install the old ext/mysql extension on PHP 7.0+. It does not exist.
  • WordPress 3.9+ uses mysqli instead. If your WordPress version is older than 3.9, update WordPress.
  • If you have custom PHP code using mysql_* functions, it must be rewritten to use mysqli_* or PDO.

Other Extensions WordPress Needs

While you are installing PHP extensions, make sure WordPress has everything it needs:

# Install all recommended WordPress PHP extensions at once:
sudo apt install php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring \
  php8.2-xml php8.2-zip php8.2-intl php8.2-imagick php8.2-bcmath

# Restart PHP-FPM:
sudo systemctl restart php8.2-fpm

WordPress will work with just mysqli, but many plugins and themes require the additional extensions listed above.

Troubleshooting

  • Extension installed but still getting the error: You may have installed for the wrong PHP version. Check which PHP version the web server uses, not the CLI.
  • Cannot find the package: Make sure you have the correct PHP repository. On Ubuntu, you may need to add the Ondrej PPA: sudo add-apt-repository ppa:ondrej/php.
  • Error after upgrading PHP: Install the MySQL extension for the new PHP version and ensure the web server is configured to use the new version.
  • Shared hosting: Contact your hosting provider — you likely cannot install PHP extensions yourself on shared hosting.

For a complete guide on setting up PHP with a web server, see Nginx, PHP, and SSL on Ubuntu.

Improve Your Websites Speed and Security

14 days free trial. No credit card required.