How to override the path of PHP to use the MAMP pa

2019-01-03 20:18发布

After screwing up entirely my PHP configuration on MAC trying to get the SOAP module working (-bash: /usr/bin/php: No such file or directory ....) I now have to use MAMP but each time I have to type the path

Applications/MAMP/bin/php5.3/bin/php to do command line.

How to just type php instead the entire path on MAC ? I double checked and i do not have a file named .profile nor bash_profile

Thanks

PS: Here's what output echo $PATH :

echo $PATH
/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin

12条回答
smile是对你的礼貌
2楼-- · 2019-01-03 20:46

Everytime you save MAMP config (PHP section), it saves the current version of PHP on ~/.profile file and creates the alias for php, pear and pecl, to point to the current configured version.

However, you need to refresh your terminal (open another session) to get this file refreshed. You can also type source ~/.profile to refesh the aliases manually.

If you want to extract this curerent version in a PHP_VERSION variable - as commented above - for further use, you can do:

export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`

And then you'll have $PHP_VERSION available with the current version of MAMP.

Finally, if you want to run your php using the current configured version on mamp, you just need to add to your ~/.bash_profile the following:

export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`
export PHPRC="/Library/Application Support/appsolute/MAMP PRO/conf/" #point to your php.ini folder to use the same php settings
export PATH=/Applications/MAMP/bin/php/php$PHP_VERSION/bin:$PATH

Now, even script that relies on /usr/bin/env php will read the correct version from Mamp config.

查看更多
Anthone
3楼-- · 2019-01-03 20:53

Sometimes, it's easier to do this:

sudo ln -s /Applications/MAMP/bin/php/php5.6.10/bin/php /usr/bin/php;

Mamps version of PHP at the time of posting was php5.6.10, so make sure you change that to the version you're using.

You'll be up in a jiffy.

查看更多
戒情不戒烟
4楼-- · 2019-01-03 20:55

I found that on Mavericks 10.8 there wasn't a .bash_profile and my paths were located in /etc/paths

In order to have the new path (whether this is a mamp or brew install of php) take effect it needs to be above the default /usr/bin/php in this paths file. eg.

/Applications/MAMP/bin/php/php5.3.6/bin
/usr/bin 

AFter the change, open a new terminal window and run 'which php' that should now point to your updated path

查看更多
叼着烟拽天下
5楼-- · 2019-01-03 20:55

you might still run into mysql binary not being found in that manner

open terminal, type
touch ~/.bash_profile; open ~/.bash_profile

edit as follows below, save, quite and restart terminal or alternately

source ~/.bash_profile

to execute new PATH without restarting terminal

and in the fashion of the DavidYell's post above, also add the following. You can stack various variables by exporting them followed by a single PATH export which I demonstrated below

export MAMP_PHP=/Applications/MAMP/bin/php/php5.6.2/bin
export MAMP_BINS=/Applications/MAMP/Library/bin
export USERBINS=~/bins
export PATH="$USERBINS:$MAMP_PHP:$MAMP_BINS:$PATH"

cheers

查看更多
趁早两清
6楼-- · 2019-01-03 20:58

This one worked for me:

sudo mv /usr/bin/php /usr/bin/~php
sudo ln -s /Application/XAMPP/xamppfiles/bin/php /usb/bin/php
查看更多
手持菜刀,她持情操
7楼-- · 2019-01-03 20:58

Probably too late to comment but here's what I did when I ran into issues with setting php PATH for my XAMPP installation on Mac OSX

  1. Open up the file .bash_profile (found under current user folder) using the available text editor.
  2. Add the path as below:

export PATH=/path/to/your/php/installation/bin:leave/rest/of/the/stuff/untouched/:$PATH

  1. Save your .bash_profile and re-start your Mac.

Explanation: Terminal / Mac tries to run a search on the PATHS it knows about, in a hope of finding the program, when user initiates a program from the "Terminal", hence the trick here is to make the terminal find the php, the user intends to, by pointing it to the user's version of PHP at some bin folder, installed by the user.

Worked for me :)

P.S I'm still a lost sheep around my new Computer ;)

查看更多
登录 后发表回答