Vijayanand Premnath
Vijayanand Premnath

Reputation: 3605

Connecting Laravel to Sqlite in Laravel 5.2

How can I connect to Sqlite db?

I have done the below things

1) Created project.
2) Created database.sqlite inside the database folder (database\database.sqlite).
3) Changed 'default' => env ('DB_CONNECTION', 'mysql'), to 'default' => env ('DB_CONNECTION', 'sqlite'), in the database.php file.
4) Ran php artisan migrate.

But I am getting an error

[InvalidArgumentException]
Database (sqlite) does not exist.

Then I tried DB_DATABASE=database\database.sqlite as stated in the documentation but I get the following error.

[PDOException]
Could not find driver

I have set the .env file as below

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database/database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret

Upvotes: 0

Views: 687

Answers (1)

Sqlite is available for the CLI, but not for PHP. You need to install it. Run the below command in terminal

$ sudo apt-get install php5-sqlite

If you're running php7, you need to install php7.0-sqlite. After that restart your apache or whatever web server you have.

Upvotes: 0

Related Questions