Deployed new Laravel app using Laravel Vapor but receiving this error "Database file at path [/var/task/database/database.sqlite] does not exist". How can I fix this issue?
The error message "Database file at path [var/task/database/database.sqlite] does not exist" indicates that Laravel is unable to locate the SQLite database file that it needs to operate. This issue can occur when deploying a Laravel application using Laravel Vapor for the first time. Here are the steps to resolve this issue:
- Check if the database service is running in Laravel Vapor:
First, ensure that the database service is running in Laravel Vapor. You can check the status of the service by visiting the Laravel Vapor dashboard or by running the following command in your terminal:
$ vapor status
If the database service is not running, start it by running:
$ vapor start
- Check if the database connection details are correct:
Next, verify that the database connection details in your Laravel .env
file are correct. Open the .env
file in your Laravel project and ensure that the DB_DATABASE
, DB_USERNAME
, DB_PASSWORD
, and DB_HOST
variables are set to the correct values for your Laravel Vapor database service.
- Check if the database file is being synced:
By default, Laravel Vapor does not sync the database file to the server. Instead, it manages the database service separately. To ensure that Laravel is using the correct database service provided by Laravel Vapor, add the following lines to your app/Providers/AppServiceProvider.php
file in the boot()
method:
if (env('APP_ENV') === 'production') {
$app->singleton('db', function () {
return new Illuminate\Database\Capsule\Manager(
config(['database.default' => 'pgsql'])
);
});
}
This code sets the default database connection to PostgreSQL, which is the database engine used by Laravel Vapor.
- Clear the Laravel cache:
Finally, clear the Laravel cache by running the following command in your terminal:
$ php artisan cache:clear
This command clears the Laravel cache, which may contain outdated database connection information.
After following these steps, your Laravel application should be able to connect to the database provided by Laravel Vapor, and the "Database file at path [var/task/database/database.sqlite] does not exist" error should be resolved.