2

I have a question about setting "$PATH" variables for PHP scripts in AMPPS (On OSX 10.10 Yosemite).

The PHP in AMPPS seems to run as my user "danny", however the $PATH it sees is different. Here's what I see from my terminal: Dannys-MacBook-Air:AMPPS danny$ echo $PATH; /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

And here is what I get within a PHP script by printing out $_ENV: ["PATH"]=> string(29) "/usr/bin:/bin:/usr/sbin:/sbin" ["USER"]=> string(5) "danny"

I tried doing "putenv()", tried doing "shell_exec" with a different $PATH, I tried doing SetEnv in .htaccess and in the Apache config file. I tried editing the systemwide /etc/.bashrc , and my users ~/.bash_profile. Neither helped so far.

All I need is to have /usr/local/bin as part of my $PATH.

3
  • Did you try to edit the file /etc/apache2/envvars ? (I'm running debian so the path may differ on OSX...) Commented Jan 27, 2015 at 9:21
  • Agree with @JuniusRendel. Doing putenv() etc. won't help you, you have to set the PATH before Apache starts. I ended up writing a small start script to modify the environment and then fire up my /opt/local/apache2/bin/apachectl (installed using MacPorts). Commented Jan 27, 2015 at 9:42
  • well, I tried adding export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin " in both of the files /Applications/AMPPS/apache/bin/envvars and /Applications/AMPPS/apache/bin/envvars-std and I'm getting the same result again ["PATH"]=> string(29) "/usr/bin:/bin:/usr/sbin:/sbin" Commented Jan 27, 2015 at 10:52

4 Answers 4

2

I know this is an older post, but this helped me, (doing this with Ampps, not MAMP, but it should work the same)

From here

Create a variable with the path to your PHP binary (in terminal)

they recommend

export AMPPS_PHP=/Applications/AMPPS/php/bin

mine was export AMPPS_PHP=/Applications/AMPPS/php-7.1/bin

then just

export PATH="$AMPPS_PHP:$PATH"

Test it out with which php or php -v

Sign up to request clarification or add additional context in comments.

Comments

0

I don't know if it is even possible, but I wonder why do you need this, i.e. do you need really to change your PATH env variable? Or it would be enough to you using this function and setting the variabile only for the created process?

1 Comment

I'd prefer not to use this way as my production server won't work this way
0

You can setup your Apache Server to run with your credential and resolve definitively the $PATH problem.
However, you can also do this and it should works :

<?php
putenv('PATH', getenv('PATH') . ';/usr/local/bin');
var_dump(getenv('PATH'));
?>

The modification of $PATH will still available only the duration of your PHP execution, there are other ways to set environment variable permanently

Hope that helps :)

2 Comments

as I said in my main question I tried both ways you just said and non of them doesn't work.
putenv() expects exactly 1 parameter, 2 given in
0

This may not be well received, but I have been in your spot and have come close to throwing my machine across the room trying to properly set the PHP path for MAMP in OSX.

I started using Vagrant and developing from a VM, and found it to be way easier, especially if you want to change languages for other projects. Trust me, it will save you time in the long run.

  1. Download VirtualBox
  2. Download Vagrant
  3. Select what type of box you want via PuPHPet
  4. cd into the puphpet directory and run vagrant up (may take a while!)

The inital setup will take a little bit of time, but be very fast moving forward and makes it really easy to share environments with others.

Cheers

EDIT: I think its a very real solution for the future, but for now what worked for me was adding: export PATH=/usr/local/php5/bin:$PATH to my .bash_profile on OSX Yosemite. I believe the folder structure changed in Yosemite.

1 Comment

Interesting, but it not a real solution.. must be a way to configure the $PATH some how.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.