4

I need to update my PATH variable within a MAMP v3.4 server.

As you can see, the PATH environment variable that Apache is using does not match the PATH that I use when I open terminal.

<?php
  passthru('env');
  die();

The script above prints out:

...
PATH=/usr/bin:/bin:/usr/sbin:/sbin
...

Meanwhile, my PATH when I run my terminal is:

$ env
  ...
  PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

I have tried the solutions offered here and here, but none have worked.

Setting an environment variable in /Applications/MAMP/conf/apache/httpd.conf seemed promising, but it doesn't work when setting PATH.

# Near the top of my httpd.conf file...
SetEnv MY_TEST_DETAIL foo
SetEnv PATH /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

I restart my MAMP server, and looked at phpinfo()

Apache Environment Variables

As you can see, it added the MY_TEST_DETAIL environment variable, but it did not change PATH.

Community
  • 1
  • 1
romellem
  • 5,792
  • 1
  • 32
  • 64

1 Answers1

6

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.

Andrew Sinagra
  • 232
  • 1
  • 4
  • 14
  • 4
    I thought I tried this before and found it didn't work (Apache wouldn't even start). After fiddling with it some more, I got it to work by commenting out the `if test "x$DYLD_LIBRARY_PATH"` block along with the final `export DYLD_LIBRARY_PATH` command. So, my `envvars` file basically just contains `export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"` at the bottom. Now, my **PATH** environment variable is changed. Thanks! Works for me. – romellem Dec 27 '16 at 14:38
  • God bless you! I had already changed that file but renaming it was what I was missing – Juan Bayona Beriso Sep 08 '17 at 10:55