Laravel 5 PDOException Could Not Find Driver

PhpMysqlLaravelLaravel 5

Php Problem Overview


I have a problem using Laravel 5. When I run "php aritsan migrate", I got this error

**************************************
*     Application In Production!     *
**************************************

Do you really wish to run this command? [y/N] y

[PDOException]
could not find driver

I could run the application, but when database connection needed, I got this error

PDOException in Connector.php line 55:
could not find driver
in Connector.php line 55
at PDO->__construct('mysql:host=localhost;dbname=mydb', 'root', '', array('0', '2', '0', false, false)) in Connector.php line 55
at Connector->createConnection('mysql:host=localhost;dbname=mydb', array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'mydb', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'name' => 'mysql'), array('0', '2', '0', false, false)) in MySqlConnector.php line 22

How to fix it?

Php Solutions


Solution 1 - Php

Same thing happend to me after upgrading distro.

Running sudo apt-get install php7.0-mysql fixed it for me.

Solution 2 - Php

You should install PDO on your server. Edit your php.ini (look at your phpinfo(), "Loaded Configuration File" line, to find the php.ini file path). Find and uncomment the following line (remove the ; character):

;extension=pdo_mysql.so

Then, restart your Apache server. For more information, please read the documentation.

Solution 3 - Php

I'm using Ubuntu 16.04 and PHP 5.6.20

After too many problems, the below steps solved this for me:

  1. find php.ini path via phpinfo()

  2. uncomment

     extension=php_pdo_mysql.dll
    
  3. add this line

     extension=pdo_mysql.so
    
  4. then run

     sudo apt-get install php-mysql
    

Solution 4 - Php

It will depend of your php version. Check it running:

php -version

Now, according to your current version, run:

sudo apt-get install php7.2-mysql

Solution 5 - Php

sudo apt-get update

For Mysql Database

sudo apt-get install php-mysql

For PostgreSQL Database

sudo apt-get install php-pgsql

Then

php artisan migrate

Solution 6 - Php

I have tried the following command on Ubuntu and its working for me sudo apt-get install php7.0-mysql

Thanks

Solution 7 - Php

If your database is PostgreSQL and you have php7.2 you should run the following commands:

sudo apt-get install php7.2-pgsql

and

php artisan migrate

Solution 8 - Php

For me the problem was that I was running the migrate command not from inside the container where php was running. The extension was properly set there but not at my host machine.

Solution 9 - Php

Uncomment database line from php.ini file according to your database type

For MYSQL

;extension=pdo_mysql

For Postgres

;extension=pgsql

Solution 10 - Php

If you have php8 installed on ubuntu 20.04, you can run this command

sudo apt-get install php8.0-mysql

Solution 11 - Php

This did trick for me.

sudo apt install php-mysql

it will install php-mysql depending on the version of php you are using

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZZZView Question on Stackoverflow
Solution 1 - PhpknaljView Answer on Stackoverflow
Solution 2 - PhptomsihapView Answer on Stackoverflow
Solution 3 - PhpAnil GuptaView Answer on Stackoverflow
Solution 4 - PhpedwinchpView Answer on Stackoverflow
Solution 5 - PhpMuhammad SulmanView Answer on Stackoverflow
Solution 6 - PhpAbdul RehmanView Answer on Stackoverflow
Solution 7 - PhpStivenson MbView Answer on Stackoverflow
Solution 8 - PhpdanielView Answer on Stackoverflow
Solution 9 - PhpHadiNiaziView Answer on Stackoverflow
Solution 10 - PhpMacdonaldView Answer on Stackoverflow
Solution 11 - PhpBercoveView Answer on Stackoverflow