0

I have a Laravel project that I need to give some maintenance, so I cloned the project, ran composer update and then tried to migrate with php artisan migrate (after creating the DB on MySQL)...

I'm on Ubuntu 20.04, using PHP 7.4 with Laravel 8.

I get this error:

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

   Illuminate\Database\QueryException 

  could not find driver (SQL: select * from information_schema.tables where table_schema = escola_da_qualidade and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:685
    681▕         // If an exception occurs when attempting to run a query, we'll format the error
    682▕         // message to include the bindings with SQL, which will make this exception a
    683▕         // lot more helpful to the developer instead of just the database's errors.
    684▕         catch (Exception $e) {
  ➜ 685▕             throw new QueryException(
    686▕                 $query, $this->prepareBindings($bindings), $e
    687▕             );
    688▕         }
    689▕ 

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

Searching here on Stackoverflow, I tried to install the library with apt-get install php-mysql, apt-get install php7.4-mysql, etc...

this is the result from php -m

[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
imagick
imap
intl
json
libxml
mbstring
openssl
pcntl
pcre
PDO
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

I've also tried uncomment extension=pdo_mysql on /etc/php/7.4/apache2/php.ini as well as in /etc/php/7.4/cli/php.ini and then restarting apache2, but still got the same error.

the default driver on laravel config/database.php is 'default' => env('DB_CONNECTION', 'mysql'), and on .env I have DB_CONNECTION=mysql

Also have tried php artisan config:cache and php artisan config:clear

Any help?

JDalri
  • 378
  • 5
  • 21
  • Does this answer your question? [Laravel 5.4 on PHP 7.0: PDO Exception - Could not find driver (MySQL)](https://stackoverflow.com/questions/42909397/laravel-5-4-on-php-7-0-pdo-exception-could-not-find-driver-mysql) – steven7mwesigwa May 25 '21 at 17:04
  • unfortunately it didn't – JDalri May 25 '21 at 17:51
  • Does this answer your question? [PHP 7.0 and MySQL start-up error "undefined symbol: mysqlnd\_allocator in Unknown"](https://stackoverflow.com/questions/38055444/php-7-0-and-mysql-start-up-error-undefined-symbol-mysqlnd-allocator-in-unknown) – mrhn May 25 '21 at 19:05

1 Answers1

0

This question was a duplicate

To fix this issue run the following

sudo apt-get remove --purge php-common
sudo apt-get update
sudo apt-get install php-common php-mysql php-cli

NOTE: Multiple versions of php can be installed. Check the version being used and install the correct modules for it.

php -v
PHP 7.4.x (cli)

Just modify the commands above for the version being used

sudo apt-get remove --purge php7.4-common
sudo apt-get install php7.4-common php7.4-mysql php7.4-cli

Big thanks to @LogGurkha

waltmagic
  • 631
  • 2
  • 9
  • 22
  • For the weirdest reason ever, which I still did'nt figured it out, my dumb terminal is installing php-common instead of php7.4-common... When executing literally apt install php7.4-common. – Raul Chiarella Jul 01 '23 at 20:35