mbnoimi's avatar

SQLite database path in .env

My project unable to connect to SQLite database under Sail. Does DB_DATABASE value is incorrect?

.env

DB_CONNECTION=sqlite
# DB_HOST=localhost
# DB_PORT=3306
DB_DATABASE=database\database.sqlite
# DB_USERNAME=sail
# DB_PASSWORD=password

I tried to use:

DB_DATABASE="database\database.sqlite"

But it failed! I think this related to absolute/relative path issue. Does it?

$ docker exec -it 1b84e0207e1d ls database
database.sqlite  factories  migrations  seeders
0 likes
8 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Dont set it in your env file. Just give it the filename if needed at resolved it in database.php

 'database'                =>  database_path(env('DB_DATABASE', 'database.sqlite')),

But in your case, you can just remove it from .env and it should work

1 like
mbnoimi's avatar

@Sinnbeck I modified it a little bit:

            'database' => env('DB_DATABASE/..', database_path('database.sqlite')),
tykus's avatar

That is the default SQLite database path; it shouldn't need the environment variable at all. In any case, make sure the directory separator is correct; for Linux it is /

database/database.sqlite
2 likes
tykus's avatar

@mbnoimi it doesn't work to comment out the line in .env - and use the default?

1 like
mbnoimi's avatar

@tykus This worked for me

DB_CONNECTION=sqlite
# DB_HOST=localhost
# DB_PORT=3306
# DB_DATABASE=database.sqlite
# DB_USERNAME=sail
# DB_PASSWORD=password
tykus's avatar

@mbnoimi right... like I said:

That is the default SQLite database path; it shouldn't need the environment variable at all.

1 like
Sinnbeck's avatar

@mbnoimi And I said :)

But in your case, you can just remove it from .env and it should work

1 like

Please or to participate in this conversation.