Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql.so'

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?

like image 355
flabbergasted Avatar asked Jun 07 '20 02:06

flabbergasted


3 Answers

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:

like image 86
LogGurkha Avatar answered Nov 15 '22 15:11

LogGurkha


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

like image 35
Thyago Ghelere Avatar answered Nov 15 '22 16:11

Thyago Ghelere


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.

like image 2
malkev Avatar answered Nov 15 '22 16:11

malkev