4 min read

Setting Up SQLite in a Laravel Application

Interested in generating passive income? Join our partnership program and receive a commission on each new client referral. Learn more.


First of all, what is SQLite?

SQLite is one of the representatives of SQL database systems best known for its simpleness and high speed. Therefore, SQLite is an excellent choice for middle-sized projects. It is small, flexible, fast, and quite simple to set up in our application.

SQLite is not a Client/Server RDBMS (Relational Database Management System); it is built-in in our application, and the data is being retrieved/stored/modified during our application process. 

With Client/Server RDBMS, our application is a separate process, and the database is another. That relation means that the connection between the database is basically a dialogue and intercommunication between computer processes. Communication within the computer processes requires extra resources and usually causes delays. In that respect, SQLite is more efficient. 

However, SQLite has its drawbacks. At any given moment, SQLite can only make one entry. So if the traffic for database entries is high, it slows down. However, fetching data from the database can be divided into different streams. Therefore, it is essential to consider how much and what kind of workload our application will have and choose the database accordingly. 

Make good choices

Prerequisites for the setting up SQLite in Laravel (Ubuntu, WSL)

To use SQLite, we need to install the appropriate package:

sudo apt install sqlite3

You also need to install the PHP extension for PHP to communicate with the SQLite database.

sudo apt install php-sqlite3

SQLite configuration in Laravel

One of the drivers of Eloquent is SQLite; therefore, setting up SQLite in Laravel means just changing the .env file. 

The standard database configuration in a .env file looks like this:

env DB configuration

The only thing we need from here is DB_CONNECTION. We can delete the rest because since SQLite is a one-file database, it doesn’t need a database name, user, or password, nor does it have any user privileges. 

Put sqlite in DB_CONNECTION and delete the rest of the parameters from .env:

env DB conection

You will also need to create an empty file in the database folder and name it as database.sqlite because generally, Laravel searches the SQLite file at that address:

SQLite database

If you want to have an SQLite database (file) on the other address, you should tweak the config/database.php and put the desired name and address of the file:

Laravel database configuration

And that’s it, 

Happy Querying ?

It is done

Written by: Giorgi Giunashvili

Translated by: Keti Getiashvili

Meet the authors

We are a 200+ people agency and provide product design, software development, and creative growth marketing services to companies ranging from fresh startups to established enterprises. Our work has earned us 100+ international awards, partnerships with Laravel, Vue, Meta, and Google, and the title of Georgia’s agency of the year in 2019 and 2021.

Contact us