Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change the PHP path to MAMPs PHP

Tags:

php

macos

mamp

I'm running PHP with MAMP on OSX 10.5.8

So if I want to run a script from console I always need to write

/applications/mamp/bin/php5.3/bin/php path/to/script

which is annoying. Is there a way to change the default path to php so that I can write

php path/to/script

and still uses MAMPs PHP version?

like image 906
Johannes Klauß Avatar asked Jun 01 '12 20:06

Johannes Klauß


4 Answers

Create a file called .bash_profile on your home directory (if you don't have this file already), and add this to the file:

export PATH=/Applications/mamp/bin/php5.3/bin:$PATH

Then quit and relaunch Terminal.app

like image 97
bfavaretto Avatar answered Nov 17 '22 11:11

bfavaretto


Use latest MAMP version of PHP

you need to edit .bash_profile

open -a TextEdit ~/.bash_profile

if you cannot find bash_profile under your home directory then create .bash_profile:

 touch ~/.bash_profile

Use latest MAMP version of PHP

PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH

(Run source ~/.bash_profile after making your changes to make sure they take effect.)

source: How to override the path of PHP to use the MAMP path?

like image 20
Amrit Shrestha Avatar answered Nov 17 '22 10:11

Amrit Shrestha


The easiest way would be to rewrite the alias. Just copy/paste the cmd bellow into terminal for temporary use or write it into .bash_profile to make it permanent.

For MAMP

$ alias php=/applications/mamp/bin/php5.3/bin/php

For XAMPP

$ alias php=/Applications/XAMPP/bin/php

For AMPPS

$ alias php=/Applications/AMPPS/php-5.6/bin/php

Run php via our new alias

$ php -v
like image 23
kjellberg Avatar answered Nov 17 '22 11:11

kjellberg


vi ~/.bash_profile

//add
export PATH=/path/to/php/bin:$PATH

source ~/.bash_profile 
like image 24
Jack Sun Avatar answered Nov 17 '22 12:11

Jack Sun