# Connecting a database to Laravel

> Learn how to connect a database to Laravel the easy way with SQLite, by setting DB_CONNECTION=sqlite in your .env so a file is created on first migration.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2023-06-10 | Topics: [Laravel](https://flaviocopes.com/tags/laravel/) | Canonical: https://flaviocopes.com/connecting-a-database-to-laravel/

We’re using Laravel in a very basic form, without any database.

Now I want to set up a database and configure Laravel to use it.

After we’ve configured the database, I’ll show you how to use forms to accept user input and store data in the database, and how to visualize this data.

I’ll also show you how you can use data from the database with dynamic routes.

### Connect the database to Laravel

The easiest way to use a database is by using SQLite. 

SQLite is just a file hosted in your site, no special setup needed.

Open the `.env` file, and instead of the default configuration

```php
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
```

add

```php
DB_CONNECTION=sqlite
```

Laravel will automatically create a SQLite database in `database/database.sqlite` the first time you run a migration.
