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
What Are the Benefits of Oo Programming? Will It Help Me Write Better Code
Best Way to Do a Weighted Search Over Multiple Fields in MySQL
PHP & MySQL: Using Group by for Categories
Phpexcel_Writer_Exception with Message "Could Not Close Zip File PHP://Output."
Sort Array by Object Property in PHP
Automatically Trimming an Mp3 in PHP
Phpexcel Reader -- Help Required
Laravel 5.1 Unknown Database Type Enum Requested
MySQL Transactions Within Transactions
Read in Text File Line by Line PHP - Newline Not Being Detected
Why Does "Echo '2' . Print(2) + 3" Print 521
PHP Random Url Names (Short Url)
How to Show an Alert Box in PHP
Does PHP Run Faster Without Warnings
Curl_Exec Printing Results When I Don't Want To