Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

forkingbeardman's avatar

Database file at path does not exist

hi, a very beginner here so pardon if this is very basic question or not the place for it. been trying to search for answers but was unable to find any. so here's my problem.

i have created a project with Laravel with breeze (react flavor) for frontend and FilamentPhp for admin panel. i am using laravel Herd for local development. i started with default sqlite configuration and everything has been working perfectly until i decided to move to mysql. i updated my env file to reflect the same, but i started getting

"Database file at path [laravel] does not exist. Ensure this is an absolute path to the database. (Connection: sqlite ....) "

error. my env file seems to be ok, i have updated config/database.php just in case to default to mysql. and i have cleared cache/config more than once. restarted services/computer, but both laravel and herd seem to believe that db connection is still sqlite.

here's the very default .env file i am using and let me know if there's anything else i can provide to help

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=laravel

DB_USERNAME=root

DB_PASSWORD=

any help would be much appreciated

0 likes
8 replies
LaryAI's avatar
Level 58

It sounds like you've correctly updated your .env file to switch from SQLite to MySQL, but Laravel is still trying to use the SQLite connection. Here are a few steps to troubleshoot and resolve this issue:

  1. Clear Configuration Cache: Sometimes, Laravel caches the configuration, and changes in the .env file might not be reflected immediately. Run the following command to clear the configuration cache:

    php artisan config:cache
    

    After clearing the cache, you can also run:

    php artisan config:clear
    

    This ensures that the application is using the latest configuration settings.

  2. Check config/database.php: Ensure that the config/database.php file is set to use the environment variables correctly. The default configuration should look something like this for MySQL:

    'default' => env('DB_CONNECTION', 'mysql'),
    
    'connections' => [
    
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
    ],
    
  3. Check for Environment File Issues: Ensure that there are no syntax errors or extra spaces in your .env file. Sometimes, invisible characters can cause issues.

  4. Restart Laravel Herd: Since you're using Laravel Herd, make sure to restart it after making changes to the .env file. This can be done by stopping and starting the Herd service.

  5. Verify Environment: Ensure that your application is running in the correct environment. You can check this by looking at the APP_ENV variable in your .env file. It should typically be set to local for development.

  6. Check for Overridden Configurations: Make sure there are no other configurations or environment files (like .env.local) that might be overriding your settings.

By following these steps, you should be able to resolve the issue and have Laravel connect to your MySQL database instead of SQLite. If the problem persists, double-check the MySQL server settings and ensure that the server is running and accessible with the credentials provided.

forkingbeardman's avatar

Needless to say i had already performed the steps suggested by Larry AI

MouteeSabouni's avatar

I think your problem is related to either caching or Laravel using .env.example for some reason, and both don't make sense, because it showed an error when you updated your .env which means it's being used by Laravel, and you have already used the following commands, I guess.

php artisan config:clear
php artisan cache:clear
php artisan config:cache

Try updating this line in config/database.php:

    'default' => env('DB_CONNECTION', 'sqlite'),

to this:

    'default' => env('DB_CONNECTION', 'mysql'),
1 like
forkingbeardman's avatar

@MouteeSabouni hey thanks for responding and sorry if i was a bit vague, but i did update that line already and it didn't help. I edited .env.example to mirror the .env just in case after you mentioned it and it did not help either. Just as a note i am able to connect to mysql service using the above config using other tools

forkingbeardman's avatar

@MouteeSabouni it may be worth noting that if i run

		php artisan config:cache

the bootstrap/cache/config.php ends up with

					'database' => 
							array (
								'default' => 'sqlite',
							 	'connections' => [...]

if i clear the config, then route correctly errors out saying

		SQLSTATE[HY000] [1049] Unknown database 'laravel' (Connection: mysql,

but migrations still fail with the same error:

		Database file at path [laravel] does not exist. Ensure this is an absolute path to the database. (Connection: sqlite
forkingbeardman's avatar

in the end i was able to solve it by deleting everything and cloning my repo and reinstalling all the dependencies. seems to work with mysql now. still have no clue why artisan would adamantly try connecting to sqlite instead of mysql

1 like
twinwebdev's avatar

I ran into this error when updating from Laravel 10 to 11. In tinker I ran config('database.default'); and saw that it was set to sqlite. I ended up needing to add this line to database/config.php.

return [
	'default' => env('DB_CONNECTION', 'mysql'),

// ... rest of the config here
];

After running php artisan config:cache it started working again.

1 like
acframe's avatar

If this is still a thing, and I must caveat that this solution may be unique to my case, but it could be that the cache location needs to be changed.

Update the CACHE_STORE env value to something different to database (which is now default). I changed mine to file and I was able then to clear my cache and update to the new database config.

Hope this helps.

Please or to participate in this conversation.