Setting Environment Variables in MAMP?

前端 未结 7 1945
孤城傲影
孤城傲影 2020-12-05 00:34

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

相关标签:
7条回答
  • 2020-12-05 01:09

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

    /Applications/MAMP/conf/apache/httpd.conf
    
    SetEnv MY_VAR theValue
    SetEnv ANOTHER thisIsTheValue
    
    0 讨论(0)
  • 2020-12-05 01:17

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

    0 讨论(0)
  • 2020-12-05 01:21

    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

    0 讨论(0)
  • 2020-12-05 01:21

    I'm assuming you're talking about a local server?

    I've noticed, if you look at the processes that apache can have multiple instance running that you might need to check. If they are, quit out of them individually, as the restart won't take the new changes until all instances are restarted. Something to try.

    0 讨论(0)
  • 2020-12-05 01:25

    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

    0 讨论(0)
  • 2020-12-05 01:27

    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

    0 讨论(0)
提交回复
热议问题