Setting Environment Variables in MAMP?

2019-01-16 19:28发布

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.

标签: php macos mamp
7条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-16 20:13

You can also set PHP environment variables in MAMP Pro (not available in MAMP) in the additional parameters for <VirtualHost>: section found in the extended tab of the hosts settings panel.

mamp setting php environment variable

Screenshot is from MAMP Pro v 3.0.3

查看更多
Root(大扎)
3楼-- · 2019-01-16 20:17

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

查看更多
\"骚年 ilove
4楼-- · 2019-01-16 20:20

But it doesn't work with El Capitan. You should disable System Integrity Protection.

original

查看更多
放我归山
5楼-- · 2019-01-16 20:21

If you still can't get your environment variables:

you may need to edit your real httpd.conf in

~/Library/Application Support/appsolute/MAMP PRO/

instead of

/Applications/MAMP/conf/apache/

Also you may need to use getenv() instead of $_ENV

查看更多
混吃等死
6楼-- · 2019-01-16 20:27

You can set your environment variables in Apache configuration...

/Applications/MAMP/conf/apache/httpd.conf

SetEnv MY_VAR theValue
SetEnv ANOTHER thisIsTheValue
查看更多
唯我独甜
7楼-- · 2019-01-16 20:27

MAMP is looking for "/Applications/MAMP/Library/bin/envvars", if the file doesn't, simply create it and add your environment variables.

查看更多
登录 后发表回答