63

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?

ZZZ
  • 1,415
  • 5
  • 16
  • 29
  • 1
    Install the PDO driver on your server. – Matt Feb 06 '16 at 11:28
  • For PHP 7.4 on Windows 10 (x64) have a look https://stackoverflow.com/questions/49333044/laravel-migration-cannot-find-driver-when-using-sqlsrv-database-in-windows/65762068#65762068 – endo64 Jan 17 '21 at 14:51

11 Answers11

127

Same thing happend to me after upgrading distro.

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

Charlie Fish
  • 18,491
  • 19
  • 86
  • 179
knalj
  • 1,454
  • 1
  • 10
  • 14
  • 4
    Not sure why this has been marked down. This worked fine for me whereas the accepted answer did not. – Brad Bird Jul 24 '16 at 15:42
  • This is the first step, then activate PDO if needed. Take care of installing the mysql plugin for the right php version you're using, not especially the 7.0 (php -v) – tomsihap Oct 15 '16 at 10:24
  • I faced this error after replacing apache by nginx. I reinstalled php7.0-mysql after all and it worked like a charm. – therealbigpepe May 14 '17 at 07:17
  • 1
    In my case, I had already installed that and it was working for the command line (using the `artisan migrate` commands) but for some reason was still failing in the application. **I needed to restart apache!** – The Unknown Dev Aug 20 '17 at 00:47
  • 3
    I would suggest running `php -v` first to see what version of PHP you are running, and then install the appropriate version – Zachary Weixelbaum Sep 27 '17 at 02:27
  • Thank you. It worked in ubuntu 18.04.4 LTS, php7.4, laravel 3.2.0 – pharask Sep 02 '20 at 20:11
  • In some cases (latest Debian I think) it's `php-mysql` – Ed Halferty Feb 11 '21 at 07:29
89

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.

tomsihap
  • 1,712
  • 18
  • 29
31

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
    
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Anil Gupta
  • 1,593
  • 1
  • 19
  • 21
18

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
edwinchp
  • 181
  • 1
  • 3
15

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

Muhammad Sulman
  • 1,611
  • 1
  • 19
  • 25
7

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

Thanks

AnNaMaLaI
  • 4,064
  • 11
  • 53
  • 93
Abdul Rehman
  • 111
  • 1
  • 3
6

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
Community
  • 1
  • 1
Stivenson Mb
  • 55
  • 1
  • 3
5

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

For MYSQL

;extension=pdo_mysql

For Postgres

;extension=pgsql
Hadayat Niazi
  • 1,991
  • 3
  • 16
  • 28
2

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

sudo apt-get install php8.0-mysql
Macdonald
  • 880
  • 7
  • 21
1

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.

daniel
  • 1,152
  • 2
  • 15
  • 33
1

This did trick for me.

sudo apt install php-mysql

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

Bercove
  • 987
  • 10
  • 18