Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some env vars in .env are not available in debug:conter --env-vars

Tags:

symfony

My .env file has the following entries, but FOO is not listed when I run bin/console debug:container --env-vars. Note however that $_ENV['FOO'] exists when I dump the variable.

FOO=1
AUTH0_CLIENT_ID=clientid
AUTH0_CLIENT_SECRET=secret
AUTH0_DOMAIN=myapp.us.auth0.com

What determines if an env var defined in .env will be available in the container?

like image 462
Coder1 Avatar asked Dec 15 '25 04:12

Coder1


1 Answers

Not really sure if this is worthy of an answer but I suppose it might help.

The Symfony .env files are really just one possible sources of $_ENV variables. There are lots of other env variables floating around and of course in production, you might not use .env at all.

So rather than save access to all env variables, the Symfony configuration system only saves those that are actually used. So in this case:

# config/services.yaml
parameters:
    foo: '%env(resolve:FOO)%'

Will result in:

bin/console debug:container --env-vars
  APP_SECRET          n/a                "84dc6de50e6f2f7af3db3f78f886840f"                                      
  DATABASE_URL        n/a                "mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7"  
  FOO                 n/a                "1"                                                                     
  MAILER_DSN          n/a                n/a                                                                     
  VAR_DUMPER_SERVER   "127.0.0.1:9912"   n/a     

For a fresh 5.1 project.

Off-topic but vaguely interesting to me at least, the above command also generates a warning

 [WARNING] The following variables are missing:
 * MAILER_DSN

MAILER_DSN is commented out in the default .env file. So I guess it is possible to use env values during configuration even if none are defined at compile time. Good way to check for spelling errors I guess.

like image 194
Cerad Avatar answered Dec 16 '25 21:12

Cerad



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!