WordPress

🔧 FIX: Your PHP installation appears to be missing the MySQL extension which is required by WordPress

Looking to run a self-managed WordPress site? Great. You’ll learn a zillion things. One of the critical part of setting up a server is the PHP MySQL extension so that WordPress can communicate with the MySQL server. If you’re getting a PHP MySQL extension error on your WordPress installation, then you probably haven’t installed it yet on your server.

In this we’ll show you how to install the correct PHP MySQL extension on your WordPress site. We’ll also make sure that you have the MySQL-Server installed on your machine.

✔ Make sure MySQL service is installed and running

Before trying to install the PHP MySQL extension, let’s first make sure that MySQL server is running on your server.

Run the following command to check MySQL server status.

service mysql status

✅ If MySQL is installed and running on your server, you should get the following response:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-07-09 20:46:12 UTC; 2 weeks 2 days ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 1097 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 46 (limit: 4656)
   CGroup: /system.slice/mysql.service
           └─1097 /usr/sbin/mysqld

⚙ If MySQL isn’t running, run the following command to start the service.

service mysql start

⚙ If MySQL-Server isn’t installed, run the following command to install the latest MySQL-Server.

apt-get install mysql-server -y

⚠ When installing mysql-server, do not chose the default authentication method, use the LEGACY authentication method to keep it compatible with WordPress.

✔ Check if PHP MySQL extension is installed

On your WordPress server, run the following command to check the PHP version installed on the machine.

php -v

The above command should output a response similar to this:

PHP 7.3.7-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Jul 10 2019 06:54:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.7, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.7-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

The first line of the response reveals your PHP version, which in the example above is PHP 7.3.

Now run the following command to see if PHP MySQL extension is enabled for the PHP version installed on your server.

dpkg --list | grep php<version>-mysql

📔 Example: If the PHP version installed on your server is PHP 7.3. Then you’ll use the command dpkg --list | grep php7.3-mysql.

If the MySQL extention is installed, you will get a response similar to this:

ii  php7.3-mysql                          7.3.7-1+ubuntu18.04.1+deb.sury.org+1         amd64        MySQL module for PHP

If PHP MySQL extension is not installed on your server, you’ll get a blank response from the grep command. In that case, we’ll install the php-mysql extension on your server.

✅ INSTALL CORRECT PHP MYSQL EXTENSION
Run the following command to install the appropriate php-mysql extension on your WordPress server.

apt-get install php<version>-mysql

📔 Example: If the PHP version installed on your server is PHP 7.3. Then you’ll use the command apt-get install php7.3-mysql.

Once you have installed the correct PHP MySQL extension on your WordPress server, restart the web server.

Apache:
servive apache2 restart

Nginx:
service nginx restart


Try running your WordPress site after completing all the instructions above. It should run without issues.

🍻 Cheers!

Write A Comment