Reputation: 581
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?
Upvotes: 45
Views: 154113
Reputation: 21
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.
Upvotes: 2
Reputation: 2034
I had this problem. fix it by running :
sudo apt-get install php8.1-mysql
Upvotes: 1
Reputation: 117
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.
Upvotes: 6
Reputation: 1631
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:
Upvotes: 123
Reputation: 121
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.
Upvotes: 7
Reputation: 311
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
Upvotes: 20