PHP Upgrade – Missing mysql extension

Problem

You upgraded PHP and now have the following error:

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

Solution

First, make sure MySQL server is running. Type the following command at a shell prompt:

# /etc/init.d/mysql status

If MySQL is not running, enter:

# /etc/init.d/mysql start

If MySQL is not installed, type the following command to install MySQL server:

# apt-get install mysql-server

For PHP5
Make sure MySQL module for php5 is installed:

# dpkg –list | grep php5-mysql

To install php5-mysql module enter:

# apt-get install php5-mysql
# apt-get install php5-mysqlnd-ms

For PHP7
Make sure MySQL module for php5 is installed:

# dpkg –list | grep php7.0-mysql

To install php5-mysql module enter:

# apt-get install php7.0-mysql

Next, restart the Apache2 web server:

# /etc/init.d/apache2 restart

If this doesnt help then you either have a misconfiguration in the php.ini or the wordpress installation may be out dated e.g. earlier than v4 and you are trying to run it on PHP7. If that is the case downgrade the PHP7 to PHP5.6 using the following command

# downgrade
sudo a2dismod php7.0 && sudo a2enmod php5.6 && sudo service apache2 restart
# For php-cli in the command line
sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php

Then upgrade wordpress.

Upgrade PHP back to PHP7

# upgrade
sudo a2dismod php5.6 && sudo a2enmod php7.0 && sudo service apache2 restart
# For php-cli in the command line
sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php

Tested Platform
Ubuntu 14
PHP 7, 5.6

Hits: 226

Leave a Reply