php artisan migrate throwing [PDO Exception] Could not find driver - Using Laravel
Solution 1
You can use
sudo apt-get install php7-mysql
or
sudo apt-get install php5-mysql
or
sudo apt-get install php-mysql
This worked for me.
Solution 2
You need to specifically enable the pdo_mysql plugin. Assuming you're using a standard PHP installation, then generally you would simply need to add this to your PHP.ini file:
extension=pdo_mysql.so
You need to ensure that this file exists in the extension directory though.
Adding pdo_pgsql.so
doesn't help because that is for PostgreSQL.
Additionally, you should ensure that you restart the web-server after you make the changes to the PHP ini file, as the changes may not be reflected otherwise.
Solution 3
This worked for me:
sudo apt-get install php5-sqlite
This installed sqlite for php5, then I ran the php artisan migrate command again and worked perfectly.
Solution 4
Ran into the same issue here, and turns out this is because PHP at the command line uses a different php.ini
file from the browser version, which is why it looks like it's loading the extension correctly when you look at phpinfo()
in a browser.
As per this answer, you just need to run:
php --ini
At the command line, which will tell you the path to the currently loaded php.ini
(probably actually a php-cli.ini
file located in the same place as your regular php.ini
file).
Once you've found that, modify it with the pdo extensions you want (in this case for MySQL):
extension=pdo_mysql.so
Or, for any other users that are on Windows using some kind of WAMP server, it probably looks like this instead:
extension=php_pdo_mysql.dll
Solution 5
I think you missed the mysql driver for php5. Execute below command:
sudo apt-get install php5-mysql
/etc/init.d/php5-fpm restart
Vamshi Vangapally
Passionate about building solutions for problems around in the form of web and mobile applications. Design thinking, Product strategy, Skill management and Ability to code are my strengths - http://vamshi.mycollect.in, http://confusedcoin.com
Updated on July 09, 2022Comments
-
Vamshi Vangapally almost 2 years
I have a bad experience while installing laravel. However, I was able to do so and move to the next level. I used generators and created my migrations. But when I type the last command
php artisan migrate
It's throwing a PDOException - could not find driver.
'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ),
That's my configuration in config/database.php.
I tried searching on stackoverflow and laravel forums and people suggest that it's PDO problem and not artisan's or php's - I followed those suggestions like adding
extension=pgsql.so extension=pdo_pgsql.so
in php.ini
No positive result. It always says
[PDOException]could not find driver.
Can someone please help resolving this.
Environment that I am using: Mac, laravel 4, MAMP PRO with php 5.4.4
-
Vamshi Vangapally about 10 yearsHow can I check if that file exists in extension directory?
-
JaTochNietDan about 10 yearsGenerally your extension directory would be where you installed PHP under in ./ext, for example on Windows it's
C:\Program Files (x86)\PHP\ext
by default using PHP's installer package. -
Vamshi Vangapally about 10 years
extension_dir ="/Applications/MAMP/bin/php/php5.4.4/lib/php/extensions/no-debug-non-zts-20100525/"
is pointing to this and that folder has all the required .so files -
JaTochNietDan about 10 yearsHave you restarted the webserver after making the appropriate changes to the PHP ini file?
-
Rick almost 10 yearsAfter setting up the configuration make sure you restart the web server sudo service apache2 restart
-
AliRNazari over 8 years
/Applications/MAMP/bin/php/php5.5.26/bin/php artisan migrate
this command worked for me. tnx a lot :* -
Zane over 8 yearsFixed my issue while trying to run
phpunit
on the main Laravel Framework. -
IIllIIll over 8 yearsThat's great! What about Mac?
-
tombrown52 over 7 yearsI don't understand why, but installing php5-sqlite caused PDO mysql to work correctly. Thanks!
-
garrettendi over 7 yearsRecent versions of Ubuntu do not contain this package. For 16.04, run:
sudo apt-get install php-sqlite3
-
Niroj Adhikary about 7 yearssudo apt-get install php-mysql This worked for me. Thanks mate
-
The Unknown Dev over 6 yearsIf you're not sure which, check your PHP version with
php --version
and install the corresponding driver. -
Bantu about 5 yearsThe linked answer help me out in my debian 9, i needed to update alternatives to php5.6. Thanks
-
Mike Robinson about 4 yearsWhen running the current version of Ubuntu, three years later, I too found that this solution solved my problem.
apt-cache search mysql | grep php
showed me that the package name I needed was nowphp7.2-mysql
... I installed it and the problem went away. -
Mike Robinson about 4 yearsWhen running the current Ubuntu, four years later, I found that this suggestion solved my problem perfectly.
-
Carlos Salles almost 3 yearsI was using WSL with a docker container inside it, when i call
php artisan test
inside the wsl, it gives the no driver error, but when i call it inside the container, it works. Installing php-mysql on wsl ( where i was running thephp artisan test
originally ) solves the problem. Thanks man! -
DavidHyogo about 2 yearsI've expanded on this in my answer. I always forget that the Apache PHP and the CLI PHP might be different.