Support the ongoing development of Laravel.io →
Configuration Database

New to Laravel. Not sure I understand the difference between these two configuration methods. I'm using 5.2. I'm following the "Laravel from Scratch" videos. In the database section, the video takes us through config/database.php, and changing the default from mysql to sqlite, and creating an sqlite file. The mysql section of that file contains variables for host, database, user, password.

Then I found that the env file contains mysql parameters too, and that these (homestead) were being used in place of what I did in config/database.php.

I found a comment below the video about defining the sqlite databse in the env file and I got things working, but I'm still confused.

What is the purpose of config/database.php? It doesn't seem to control anything. It seems that best practice is to work with the env file, since you can have one for dev and one for prod.

Any help in undestanding this will be appreciated.

Last updated 3 years ago.
0

That file (config/database.php) is the actual configuration file that will be used. That file just happens to pull some values from the env. This allows you to not have to change the config files themselves when you have a project on different servers. You can just have a different .env file on each host that specifies its unique values for those.

Imagine you are working with other people. They will have different configuration for their database. Having to hardcode values into the config file that is committed to a repository would end up with some problems as they pull down changes their configs might get overwritten. The .env file is not committed and should not be as its unique to the 'host'.

By having the config files pull values from env, each person (host) can have their own .env file with their own values without having to make changes to the actual config files.

0

After reading your post, learning what the env() function does at https://laravel.com/docs/5.0/helpers and reviewing the contents of the config/database.php, I get this. Thanks.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.