46

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?

6 Answers 6

125

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:

Sign up to request clarification or add additional context in comments.

7 Comments

This helped. In my case I just replaced php-* with php7.4-*.
i just replaced to sudo apt-get install php7.4-common php7.4-mysql php7.4-cli
In my case, I had to command sudo apt-get install php at the end.
Worked great for me after a reboot.
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.
|
21

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

Comments

7

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.

4 Comments

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?
I solved the problem following this advice askubuntu.com/a/187278/885417
This worked for me using php version 8.2.10
For me it worked using the full path and file name: extension=/usr/lib/php/20220829/pdo_mysql.so
6

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.

1 Comment

This is for Windows OS.
2

Alok Dev’s answer worked for me, but with a potentially significant caveat of accidentally uninstalling other dependency apt packages (in my case zoneminder). A safer workflow would be to use the dry-run flag first to determine what all would be removed.

sudo apt-get --dry-run --purge remove php-common

Back up your system, then remove php-common and reinstall, making sure to include any important packages that were uninstalled.

Another key point is to install the correct php version packages on reinstallation. For php8.2, this would be sudo apt-get install php8.2-mysql

As a side note, if you ran into this error when attempting to install Pi-hole from source, this reinstallation of php resolved that issue for me as well.

Comments

1

I had this problem. fix it by running :

sudo apt-get install php8.1-mysql

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.