0

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 vars Commented Jun 12, 2017 at 15:52
  • what about .yml or .ini formats, many use them too.. Commented Jun 12, 2017 at 15:56

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

.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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.