php artisan migrate : [PDOException] could not find driver

diEcho picture diEcho · Oct 2, 2014 · Viewed 22k times · Source

My system config is Ubuntu 14.04 + XAMPP + Laravel 4 installed

mysql driver is configured on /opt/lampp/htdocs/larva/app/config/database.php

'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'db_larva',
            'username'  => 'root',
            'password'  => '*****',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => 'tbl_',
        ),

PDO extension is enabled on /opt/lampp/etc/php.ini

extension=php_pdo_mysql.dll

create table using

php artisan migrate:make create_users --create=users 

which generate 2014_10_02_114459_create_users.php

php artisan migrate:make create_orders --create=orders

create 2014_10_02_054103_create_orders.php

now on terminal what I did

cd /opt/lampp/htdocs/larva/ 
php artisan migrate

it gives error

[PDOException] could not find driver

when i run

php artisan migrate --database=db_larva

it again gives other error

[InvalidArgumentException]
Database [db_larva] not configured.

Please guide me what I am doing wrong?

My guess:

  • Is location correct? do run php artisan inside the root folder?

  • Default table structure inside function up() need to write some more code, may be db connection settings

  • difference between php artisan migrate:make create_users --create=users and php artisan migrate:make create_users --create --table=users
  • I have to configure database settings somewhere else too.
  • table prefix can be problematic.
  • I haven't write single line to connect database, anywhere in the code yet. where to write the connection sting in code, or that is a later stage?

  • php --ini gives different path of php ini?

    Configuration File (php.ini) Path: /etc/php5/cli
    Loaded Configuration File:         /etc/php5/cli/php.ini
    Scan for additional .ini files in: /etc/php5/cli/conf.d
    Additional .ini files parsed:      /etc/php5/cli/conf.d/05-opcache.ini,
    /etc/php5/cli/conf.d/10-pdo.ini,
    /etc/php5/cli/conf.d/20-json.ini,
    /etc/php5/cli/conf.d/20-mcrypt.ini,
    /etc/php5/cli/conf.d/20-readline.ini,
    /etc/php5/cli/conf.d/20-xdebug.ini
    

Answer

Naimuddin Bhuyan picture Naimuddin Bhuyan · Feb 20, 2016

I got this error on xubuntu 14.04. I fixed it in 2 steps:

  1. Open a terminal and run sudo apt-get install php5-mysql
  2. change the db-host to 127.0.0.1 (instead of using localhost)