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
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With