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?
2
-
Personally I don't mind any approach to this, if you go with any file based solution that isn't a .php file, make sure to keep it outside your web accessible folders, I will just add that I am a fan of .ini files, as php has a handy little function to convert them into php varsDale– Dale2017-06-12 15:52:14 +00:00Commented Jun 12, 2017 at 15:52
-
what about .yml or .ini formats, many use them too..Lawrence Cherone– Lawrence Cherone2017-06-12 15:56:31 +00:00Commented Jun 12, 2017 at 15:56
Add a comment
|
2 Answers
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).