Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel says the SQLite database file does not exist

ErrorSQLiteDatabaseDoesNotExistException

Short answer

Laravel checks the SQLite file before it connects, and it throws SQLiteDatabaseDoesNotExistException when it cannot resolve the path in DB_DATABASE. The file was never created, the path is wrong or relative, or a DB_URL value overrides the path you edited. Create the file and set an absolute path.

  • Applies to Laravel 12, PHP 8.3, SQLite 3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the connection Laravel actually uses and the path it resolved. This shows whether the file name comes from your .env or from somewhere else.

    grep -E '^DB_' .env
    ls -l database/
  2. 2Match what you see, then jump to its fix

    1. 1The exception names the configured path, and nothing exists thereThe SQLite file was never createdFix
    2. 2The configured value is a bare word such as laravel, or a relative pathDB_DATABASE holds a name or a path that does not resolveFix
    3. 3You changed DB_DATABASE and the exception still names an old pathA database URL overrides the path you editedFix

What does the error look like?

  • SQLiteDatabaseDoesNotExistException

Cause 1 of 3

The SQLite file was never created

1Check

SQLite keeps the whole database in one file, and Laravel does not make it for you when you point at a new path. List the folder to see if the file is there.

ls -l database/

2Fix

Create an empty file at the path, then run your migrations.

touch database/database.sqlite
php artisan migrate

3Verify

The file now exists and the connection opens.

php artisan db:show

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

DB_DATABASE holds a name or a path that does not resolve

1Check

Laravel tries the value as given and then relative to the application base folder. A leftover MySQL-style database name does not match any file, so the lookup fails. Check what .env sets.

grep -E '^DB_' .env

2Fix

Set the connection to sqlite and put the absolute path to the file in DB_DATABASE.

DB_CONNECTION=sqlite
DB_DATABASE=/var/www/my-app/database/database.sqlite

3Verify

Run a command that opens the connection.

php artisan db:show

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

A database URL overrides the path you edited

1Check

When the url option (the DB_URL variable) is set, Laravel takes the connection details from it instead of the separate values.

grep -E '^DB_URL' .env

2Fix

Remove DB_URL, or change it to point at the same SQLite file.

# .env: delete the DB_URL line, then keep
DB_CONNECTION=sqlite
DB_DATABASE=/var/www/my-app/database/database.sqlite

3Verify

Open the connection and read the database overview.

php artisan db:show

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Keep one absolute DB_DATABASE value per environment in the deploy settings.
  • Create the SQLite file in your setup script, before the first migrate.
  • Do not leave a DB_URL in .env unless you mean it to win.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.