31

I ran the command:

php -v

Output:

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql.so' (tried: /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: mysqlnd_allocator), /usr/lib/php/20170718/pdo_mysql.so.so (/usr/lib/php/20170718/pdo_mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

I ran this command:

php -m

Output:

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql.so' (tried: /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: mysqlnd_allocator), /usr/lib/php/20170718/pdo_mysql.so.so (/usr/lib/php/20170718/pdo_mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
    [PHP Modules]
    bz2
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    intl
    json
    libxml
    mbstring
    openssl
    pcntl
    pcre
    PDO
    Phar
    posix
    readline
    Reflection
    session
    shmop
    SimpleXML
    soap
    sockets
    sodium
    SPL
    standard
    sysvmsg
    sysvsem
    sysvshm
    tokenizer
    wddx
    xml
    xmlreader
    xmlwriter
    xsl
    Zend OPcache
    zip
    zlib

    [Zend Modules]
    Zend OPcache

The php.ini file contains this line:

extension=pdo_mysql

Ran this command:

sudo apt-get install -y php-pdo-mysql

Nothing is installed, because it is already installed.

Ran this command:

php -i

Output shows:

PDO

PDO support => enabled
PDO drivers =>

Not sure why this is or what to do. Any suggestions?

Shadow
  • 33,525
  • 10
  • 51
  • 64
flabbergasted
  • 441
  • 1
  • 4
  • 8

5 Answers5

95

I solved the problem this way:

sudo apt-get --purge remove php-common

sudo apt-get install php-common php-mysql php-cli

Now there is no error and php -m shows it has everything:

LogGurkha
  • 1,272
  • 7
  • 15
  • 9
    This helped. In my case I just replaced php-* with php7.4-*. – jiv-e Nov 04 '20 at 10:38
  • 4
    i just replaced to sudo apt-get install php7.4-common php7.4-mysql php7.4-cli – Suliman Farzat Mar 31 '21 at 22:57
  • In my case, I had to command sudo apt-get install php at the end. – donkey Sep 29 '22 at 22:34
  • Worked great for me after a reboot. – enceladus Feb 11 '23 at 22:52
  • This is the best solution for such an issue. It worked for me quite fast and nice! – Erick Mar 14 '23 at 08:45
  • 1
    Warning: this worked for me, but I lost (and had to re-install) also XDebug and PHPUnit. So, before you try this solution, you better take note of all PHP tools you need. – Borjovsky Jun 13 '23 at 13:30
  • This solution gives a huge problem - When trying to purge php-common, I get: `Warning, the following packages will be removed: libapache2-mod-php8.0* php-common* php8.0* php8.0-cli* php8.0-common* php8.0-curl* php8.0-fpm* php8.0-gd* php8.0-mysql* php8.0-opcache* php8.0-readline* php8.0-zip*` – Raul Chiarella Jul 01 '23 at 20:13
17

You are probably using php7.2, so you should edit the php.ini file (/etc/php/7.2/cli/php.ini).

And probably extension=pdo_mysql on line 906 is uncommented. Comment this line by adding ; at the beginning of the line.

After saving and closing php.ini the error should disappear, however, to ensure that the changes take effect, restart the php service:

$ sudo systemctl restart php7.2-fpm

Thyago Ghelere
  • 181
  • 1
  • 5
4

Make sure that the location of pdo_mysql.so file is the same of the PHP extension_dir:

# php -i|grep extension_dir
# find / -name pdo_mysql.so

By doing this, and adding the absolute path on the php.ini like this:

extension=/usr/lib/php/20190902/pdo_mysql

this will work.

Community
  • 1
  • 1
malkev
  • 76
  • 2
  • For first command I get: extension_dir => /usr/lib/php/20170718 => /usr/lib/php/20170718 and for second command I get /usr/lib/php/20170718/pdo_mysql.so. I assume this means it's in the correct location? – flabbergasted Jun 09 '20 at 03:02
  • 1
    I solved the problem following this advice https://askubuntu.com/a/187278/885417 – flabbergasted Jun 09 '20 at 04:02
1

I have 7.4 php version. I solved this by uncommenting the following line by removing ; inside the php.ini file.

extension_dir = "ext"

Note that initially, you won't have php.ini file so first you should copy and paste php.ini-development file and rename it as php.ini.

oybek
  • 29
  • 1
0

I had this problem. fix it by running :

sudo apt-get install php8.1-mysql
Zahra Badri
  • 1,656
  • 1
  • 17
  • 28