Setting Environment Variables in MAMP?
macos, mamp, php
Solution
MAMP will load the contents of `/Applications/MAMP/Library/bin/envvars` into its environment variables when starting apache. So you can edit the file and add:
MY_VAR="foo"
export MY_VAR
Then access that variable like so:
echo $_ENV["MY_VAR"];
prints:
foo
Update for OSX Yosemite:
rename `envvars` to `_envvars`
See: MAMP Pro 3.05 on Mavericks updated to Yosemite - Apache does not start
Problem
I assume that MAMP environment variables can be set in ~/.bash_profile, but it seems that setting them there does not always take effect right away. For instance, I just set a variable in my .bash_profile and have tried restarting MAMP servers, restarting MAMP itself, and even logging out of my computer and nothing seems to work. The variable is still not accessible from within my environment. Is there another way to set MAMP env vars that I'm missing or is there a cache that I need to clear? Thanks in advance.