Danny
Danny

Reputation: 871

setting "$PATH" variables for PHP in AMPPS (OSX)

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.

Upvotes: 2

Views: 5261

Answers (4)

wellthatdidn'twork
wellthatdidn'twork

Reputation: 193

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

Upvotes: 2

cpk
cpk

Reputation: 809

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.

Upvotes: 0

Halayem Anis
Halayem Anis

Reputation: 7785

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 :)

Upvotes: 0

mgaido
mgaido

Reputation: 3055

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?

Upvotes: 0

Related Questions