Using Laravel with a SQLite database

Sep 2, 2018 by Thibault Debatty | 15955 views

Laravel PHP

https://cylab.be/blog/1/using-laravel-with-a-sqlite-database

For a development environment or for small web applications, a SQLite database may be perfectly sufficient to store your data. It is also much lighter than a full blown MySQL database.

To use a SQLite database in your Laravel project:

  1. Modify your .env :

    DB_CONNECTION=sqlite
  2. Modify config/database.php:

    connections => sqlite
    'database' => __DIR__ . '/../storage/app/db.sqlite',

    I always recommend to put your SQLite database in the storage directory, as this directory should be the only one where your web server will have write permission.

  3. Finally, create the database file:

    touch storage/app/db.sqlite

Troubleshooting

You might come across an error message stating SQLite : unable to open database

The error message unable to open database can actually be misleading. To insert data in a database (/path/to/db.sqlite for example), SQLite requires that:

  • the database file is writable;
  • and the containing folder must be writable too! (/path/to in the example)

Hence one possible solution may be to check whether the directory containing your SQLite database is writable.

This blog post is licensed under CC BY-SA 4.0

This website uses cookies. More information about the use of cookies is available in the cookies policy.
Accept