A tutorial for downloading, installing and configuring SQLite database in Windows and using it in a Laravel project.
🌍 The French version of this publication : Comment installer, configurer et utiliser SQLite avec Laravel sur Windows
What is SQLite?
SQLite is a library that provides a relational database engine, accessible via SQL (Structured Query Language). Unlike other relational database management systems such as MySQL, PostgreSQL or Oracle, it has certain differences:
- It does not require a dedicated server. It is not client/server
- It is stored as a file in the application, providing a local data storage solution.
- It is often used for mobile and desktop applications because it requires few system resources.
- ...
In this tutorial, we'll show you how to download, install and configure SQLite in Windows, so you can set it up and use it in a Laravel project.
At the time of writing, I'm using Laravel version 10.14.1
.
Installing SQLite in Windows
Here are the steps for installing and configuring SQLite in Windows :
1. Download the sqlite-dll
and sqlite-tools
precompiled archives of SQLite for Windows from the official website :
2. Extract the contents of these archives into a folder of your choice. For my part, I extract to C:\laragon\bin\sqlite
3. Add the path to the folder containing the SQLite executable to the Windows PATH
environment variable.
To do this, press Windows
+ R
to open the "Run" dialog box, type sysdm.cpl
and press "Enter". This opens the "System properties" dialog box, go to the "Advanced system settings" tab and click on "Environment variables".
Select the Path
variable in the "User variables" or "System variables" section, then click on "Edit" :
Add the path to the folder containing the SQLite executable to the list of paths by clicking on "New":
4. To ensure that SQLite is installed correctly, open the command prompt and run the sqlite3
command. This will display the sqlite >
prompt:
Enter the .quit
command to exit
Using SQLite in Laravel
Here are the steps for using SQLite in a Laravel project:
1. Create a database.sqlite
file in the /database
folder. As a reminder, this folder contains migrations, seeders, factories, etc.
2. In the .env
file at the project root, comment out the other database connection lines and enter sqlite
for the DB_CONNECTION
parameter:
DB_CONNECTION=sqlite
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=database
#DB_USERNAME=root
#DB_PASSWORD=
To understand how this works, look at the following lines in the /config/database.php
configuration file:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
// ...
],
When sqlite
is specified as the "driver" for the connection, the DB_DATABASE
database is database_path('database.sqlite')
by default.
3. Finally, run the php artisan migrate
command to migrate the tables to your database.
Take care! 😎