Home » Php » How to fix the issue:Your PHP installation appears to be missing the MySQL extension

How to fix the issue:Your PHP installation appears to be missing the MySQL extension

Posted by: admin February 25, 2020 Leave a comment


Environment:os and apache and php and mariadb version.

uname -a
Linux MiWiFi-R3-srv 4.9.0-11-amd64 #1 SMP Debian 4.9.189-3+deb9u2 (2019-11-11) x86_64 GNU/Linux

sudo apachectl -v
Server version: Apache/2.4.25 (Debian)
Server built:   2019-10-13T15:43:54

php -v
PHP 7.0.33-0+deb9u6 (cli) (built: Oct 24 2019 18:50:20) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33-0+deb9u6, Copyright (c) 1999-2017, by Zend Technologies

Login mariadb with password and input status:

Server:         MariaDB
Server version:     10.1.41-MariaDB-0+deb9u1 Debian 9.9

Check php-mysql:

sudo dpkg -l php-mysql
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
ii  php-mysql      1:7.0+49     all          MySQL module for PHP [default]

Get the mysql.so library:

sudo find  /  -name  "*mysql.so"

Chekc all modules which contain mysql:

php -m |grep  mysql
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_pdo_mysql.so' - /usr/lib/php/20151012/php_pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0

sudo vim  /etc/php/7.0/fpm/php.ini


; ... or under UNIX:







Restart apache2 and mariadb database,the issue remains ,none of the three format can work,how to fix then?

How to&Answers:

pdo_mysql is not the same as mysql.so. The old mysql extension was removed in PHP 7.0. The supported extension is now only mysqli.

From there on it depends on what the software is expecting to find – if it needs the old mysql library, then you’re going to have to use a shim or an older PHP version (i.e. anything before PHP 7, such as PHP 5.6).

You can use the php7-mysql-shim library or the mysql-shim library (be aware, this might incur a small performance penalty) to make a transparent mapping available that dispatches any calls to the old mysql library to the still supported mysqli library. As long as you’ve installed php7-mysql-shim through composer and your project uses composer, it should be loaded automagically.

A third option is to run the original code through the mysql-to-mysqli rector configuration, but if this is not your own code, that will be hard to maintain in the future.

The .so file that can’t be loaded might be because of permission issue. Make sure to ls -al that file and correct any ownership or permission issues (chmod og+r <filename>, probably).


Avoid using a quick fix that will make your application support the old php-mysql driver. There is a reason that it was removed from php.

You can use the successor of php-mysql which is the MySQLi driver, the name MySQLi actually means MySQL-improvedand as you can understand is an improved version of the MySQL driver that gives the developer more benefits.

You may also use the PHP Data Objects (PDO), an extension that defines a lightweight, consistent interface for accessing databases (MySQL is one of them) in PHP.

This would mean that you would have to re-write pieces of code related with database handled information. If you wrote a class for it then you only need to re-write that class only. If all the MySQL related functions are written in all your application then you have a lot of work.


Do some further reading of your own to judge for yourself what would be the best practice for this situation, MySQLi Wiki, Introduction to PDO, MySQLi Overview.


Remove php and related packages.

sudo apt-get autoremove php7*
sudo find /etc -name "*php*" |xargs  rm -rf 
sudo apt purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`


dpkg -l | grep php7.0


sudo apt-get install php php-mysql

At last my issue solved.


MatsLindh is right, mysql is deprecated from php 7, it seems that you have deployed old php5 code on the server that is why you received this error, now you can do two things

  • either install php5.6 and select the version for that website folder depending on which hosting you have and restart the server
  • or you can upgrade the code to php 7+ either yourself or by using tools which I do not know if it works perfectly, recently I came across this
    Rector Tool for upgrading php legacy code

We were down the same path in previous months and and we updated mysql code to mysqli and also updated the classes declarations and added the necessary checking, fixed the error handling and we were able to run the legacy app on the php 7 successfully.
Sometime due to complicated development, it is not possible to upgrade in an instant and it is also not possible to start from the scratch either because of the business logic introduced over the years so changes can only be introduced with baby steps, I can say this because we handle our high traffic ecommerce site.


As others have stated, though without a source, the mysql extension (ext/mysql) was deprecated in 5.5 (per RFC: ext/mysql deprecation) and removed in 7.0 (per RFC: Remove deprecated functionality in PHP 7).

(This is the git commit that actually removed ext/mysql from PHP, as linked to from the removal RFC – this link was added by the RFC author [nikic])

This is also mentioned all throughout the ext/mysql manual on php.net, though it doesn’t link to any other notes concerning the deprecation and subsequent removal.

If you view the backwards-incompatible changes page for 7.0 then it further mentions that all mysql extension functions were removed, and provides a link to help in choosing a new MySQL API. This provides the support and path necessary for moving on from ext/mysql.