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!
I tried to use WordPress to make RASPBERRYPI a server, but Iâm getting this error. The OS is RASPBIAN based on Debian, but the error does not disappear even though php7.3-mysql is already installed. So you canât get to the WordPress screen. Please help.
When I did it, apt-get install mysql-server -y was replaced with mariadb-server-10.0.