Ziyadin Shemsedinov
Ziyadin Shemsedinov

Reputation: 367

Should I use .env config file or just php array config?

I need environment specific config file which will not be included in the version control, file with php array seems to be a good choice especially considering that I can define values in desired type and will not need to convert them, but a lot of frameworks and libs use .env files. What are the advantages of .env files and why one should be using them?

Upvotes: 0

Views: 964

Answers (2)

Stefan Yohansson
Stefan Yohansson

Reputation: 667

I like the way Laravel do it. It implements the config file and env file.

in config/*.php, you'll define things like:

<?php
      // config/app.php
      return array(
          'myconfig' => env('MYCONFIG', 'default')
      )

in .env file

MYCONFIG=something

so you'll only need to use config function everywhere.

config('app.myconfig')

btw, it's easy to implement both (isolated or together).

Upvotes: 3

Dominique Vienne
Dominique Vienne

Reputation: 415

.env files are a standard. It is simple to use and as it sounds like, it is environment independant.

You should definitively use this solution

Upvotes: 1

Related Questions