3

I need to set environment variables inside ddev's web container. How can I do that? I've seen techniques that override the nginx configuration and such but that sounds too hard.

rfay
  • 9,963
  • 1
  • 47
  • 89

1 Answers1

5

You can use the web_environment in .ddev/config.yaml or ~/.ddev/global_config.yaml. For example,

web_environment:
- SOMEENV=somevalue
- SOMEOTHERENV=someothervalue

More on this topic in the docs.

rfay
  • 9,963
  • 1
  • 47
  • 89
  • What if you want to do it at runtime? Like `ddev exec MYVAR=123` doesn't seem to work. – dmgig Apr 22 '22 at 16:52
  • 1
    @dmgig environment variables are only in the scope of the shell they're run in, so if you use something like `ddev exec 'export JUNK=junk; echo $JUNK'` it will work fine... but it doesn't change what's inside the container. It only changes the shell command you're executing in. BTW, this answer is very old and there are much better ways now, I'll update this. – rfay Apr 25 '22 at 17:44