简体   繁体   中英

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?

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).

.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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM