Van Morrison - September 26, 2018
If you get this error, first of all, don’t panic. It is not critical and it can be easily solved.
Assuming you have absolute control of the operating system, you will first have to connect to your server via SSH, I recommend using Putty
Once logged in, check the php version currently used by the operating system:
***
# php -v
PHP 5.6.36 (cli) (built: Jun 26 2018 20:34:01)
Copyright (c) 1997-2016 The PHP Group
***
Most common used php version are 5.X and 7.
Now, what is the mysql extension needed by php and what does it do?
WordPress is a PHP and SQL based CMS (Content Management System) widely used due to its user friendliness. For PHP to be able to communicate with (perform queries on) MySQL, it uses this extension.
The extension is not always set up by default in the operating system when PHP is included. Luckily, the solution is, most of the time, very simple.
I will assume you are logged in as the ‘root’ user. Based on your operating system:
– CentOS / RedHat / Oracle Linux:
— for php 5.x:
***
# yum update
# yum install php-mysql
# service httpd restart; service apache restart; service apache2 restart; service nginx restart
***
— for php 7.x:
***
# yum update
# yum install php70w-mysql
# service httpd restart; service apache restart; service apache2 restart; service nginx restart
***
– Ubuntu / Debian
— for php 5.x
***
# apt-get update
# apt-get install php5-mysqlnd
# service httpd restart; service apache restart; service apache2 restart; service nginx restart
***
— for php 7.x
***
# apt-get update
# apt-get install php7.0-mysql
# service httpd restart; service apache restart; service apache2 restart; service nginx restart
***
This should solve the issue.
If you still get the error message, there are some other things you can check and fix.
Misconfiguration of the PHP extension folder
Go to the root folder of you website (usually public_html or www), create an info.php file and enter the following 3 lines:
<?
phpinfo();
?>
Access the file in a browser – http://yourdomain/info.php and look for „Loaded Configuration File”:
Second, look for „extension_dir”
and make sure that “extension_dir” is pointing to the correct extension folder path of the PHP version used.
If this is not the case, edit the php.ini file displayed at Configuration File and enter the correct path.
Custom php.ini for your website
If your website has a custom PHP configuration and you are upgrading or migrating the website, the .ini files will not be loaded by the other operating system components. Solution: edit your custom php.ini file and comment the following two lines:
***
; extension=mysql.so
; extension_dir=/path/to/extensions/
***
Multi-PHP and suPHP_ConfigPath is used.
If you are in a multi-PHP environment and suPHP might be used as the PHP handler, your custom PHP configuration is loaded using „suPHP_ConfigPath”.
Try to comment the suPHP_ConfigPath line(s) in the .htaccess file of your website’s root folder and see if the error message disappears.
Some Ubuntu versions
Later Ubuntu versions tend to use the MySQL drivers instead of the PHP library. For php 5.x this can be solved by installing php5-mysqlnd-ms:
***
# apt-get install php5-mysqlnd-ms
***
Control Panel options.
If you are in charge of a WHM / cPanel server (you have WHM access), you can use the web GUI to install the missing module.
From the WHM interface, enter in the search field ‚EasyApache’, click on EasyApache 4 and click Customize on the Currently Installed Packages on top of the page:
Go directly to PHP Extensions
In the search field, enter ‚mysql’. You will see a list of available php extensions:
Depending on your php version, make sure the extension is enabled. My suggestion is to activate it for every php version to save you some time if you need them in the future.
If you are not in charge of the WHM server and only have cPanel access, some hosting providers allow you to enable / disable PHP extensions.
Access the cPanel interface and navigate to Software and Services -> Select PHP Version -> PHP Selectors | Extensions. Enable mysql, mysqli and mysqlnd:
And hit Save.
Last, if you are using the Plesk control panel and none of the above applicable steps help, you should try to switch to the native PHP shipped by Plesk.