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

135,350

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
Share:
135,350
Vamshi Vangapally
Author by

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, 2022

Comments

  • Vamshi Vangapally
    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
    Vamshi Vangapally about 10 years
    How can I check if that file exists in extension directory?
  • JaTochNietDan
    JaTochNietDan about 10 years
    Generally 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
    Vamshi Vangapally about 10 years
    extension_dir ="/Applications/MAMP/bin/php/php5.4.4/lib/php/extensions/no-‌​debug-non-zts-201005‌​25/" is pointing to this and that folder has all the required .so files
  • JaTochNietDan
    JaTochNietDan about 10 years
    Have you restarted the webserver after making the appropriate changes to the PHP ini file?
  • Rick
    Rick almost 10 years
    After setting up the configuration make sure you restart the web server sudo service apache2 restart
  • AliRNazari
    AliRNazari over 8 years
    /Applications/MAMP/bin/php/php5.5.26/bin/php artisan migrate this command worked for me. tnx a lot :*
  • Zane
    Zane over 8 years
    Fixed my issue while trying to run phpunit on the main Laravel Framework.
  • IIllIIll
    IIllIIll over 8 years
    That's great! What about Mac?
  • tombrown52
    tombrown52 over 7 years
    I don't understand why, but installing php5-sqlite caused PDO mysql to work correctly. Thanks!
  • garrettendi
    garrettendi over 7 years
    Recent versions of Ubuntu do not contain this package. For 16.04, run: sudo apt-get install php-sqlite3
  • Niroj Adhikary
    Niroj Adhikary about 7 years
    sudo apt-get install php-mysql This worked for me. Thanks mate
  • The Unknown Dev
    The Unknown Dev over 6 years
    If you're not sure which, check your PHP version with php --version and install the corresponding driver.
  • Bantu
    Bantu about 5 years
    The linked answer help me out in my debian 9, i needed to update alternatives to php5.6. Thanks
  • Mike Robinson
    Mike Robinson about 4 years
    When 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 now php7.2-mysql ... I installed it and the problem went away.
  • Mike Robinson
    Mike Robinson about 4 years
    When running the current Ubuntu, four years later, I found that this suggestion solved my problem perfectly.
  • Carlos Salles
    Carlos Salles almost 3 years
    I 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 the php artisan test originally ) solves the problem. Thanks man!
  • DavidHyogo
    DavidHyogo about 2 years
    I've expanded on this in my answer. I always forget that the Apache PHP and the CLI PHP might be different.