Setting Environment Variables in Mamp

Setting Environment Variables in MAMP?

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

Change PATH Environment Variable in MAMP

In MAMP 4.0.6 for OSX I was able to update the Apache Environment Path by doing the following:

First check /Applications/MAMP/Library/bin/apachectl for a line with the comment:

#pick up any necessary environment variables

Just below this line you should see a path to where MAMP will load environment variables.

Mine said:

/Applications/MAMP/Library/bin/envvars

In the /Applications/MAMP/Library/bin path you should see a file named envvars_.

Copy this file and rename to envvars and add the following line:

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"

Now restart your MAMP servers. The phpinfo should now have the updated path information.

MAMP: Environment variables being deleted/replaced between envvars and runtime

The culprit here ended up being FastCGI. By default, it clears all environment variables from your PHP scripts. Security feature, I guess.

With MAMP, there's not a way to turn that clear_env setting off globally. But if you edit the appropriate /Applications/MAMP/fcgi-bin/phpX.Y.Z.fcgi file, you can add a line like so:

export PATH='/my/unique/custom/path'

...and you're in business.

Make sure you add that line above the last line already in the file that begins with exec.



Related Topics



Leave a reply



Submit