Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php artisan migrate throwing [PDO Exception] Could not find driver - Using Laravel

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

like image 282
Vamshi Vangapally Avatar asked Mar 17 '14 19:03

Vamshi Vangapally


4 Answers

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.

like image 68
narendro Avatar answered Nov 20 '22 15:11

narendro


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.

like image 39
JaTochNietDan Avatar answered Nov 20 '22 15:11

JaTochNietDan


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.

like image 20
Alex Avatar answered Nov 20 '22 14:11

Alex


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
like image 13
Leith Avatar answered Nov 20 '22 15:11

Leith