Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuration priority - best practise

When creating a new application that has some configuration. The configuration can exist in one of the following places

  • Env' variable
  • Config file
  • Command line
  • Default

The question is what is the priority between them? For example, if I pass a configuration from the command line it will override the config file value for this configuration

like image 402
Mzf Avatar asked Oct 31 '25 01:10

Mzf


1 Answers

So to me the priority is in that order from high to low:

command line (overrides everything bellow), environment variable, config file and default.

In general command line arguments should be able to override all config values.

Environment variables should be able to override config file values but not command line arguments. If you want to override config file value with environment variable then: X=3 that overrides config file value X=1 and then with X=2 should be done via the command line.

I think that is the most flexible way to manage this kind of hierarchy.

like image 175
gsone Avatar answered Nov 02 '25 22:11

gsone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!