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
This is not an ideal solution as you have to manage two ini files however, I managed to work around this on windows by copying the php ini file in mamp from the conf folder to your active php version in the bin folder.
[MAMP INSTALL]\conf\[ACTIVE PHP VERSION]\php.ini
copy to
[MAMP INSTALL]\bin\php\[ACTIVE PHP VERSION]
If you have to type
in your command line then add
to your PATH to be able to call php from anywhere.
To compliment the current accepted answer, if you assume that MAMP uses the most recent version of php5 as the default, you can add grep 'php5' in the middle:
and you are guaranteed to get the most recent php5 regardless of MAMP version.
The fact that the previously accepted answer refers to php 5.3.6, while the current version of MAMP ships with 7.2.1 as the default (as of early 2018), points out that this is not a very sustainable solution. You can make your path update automatically by adding an extra line to your
.bash_profile
to get the latest version of PHP from/Applications/MAMP/bin/php/
and export that to your path. Here’s how I do it:(Use
source ~/.bash_profile
after making your changes to make sure they take effect.)As others have mentioned, you will likely also want to modify your shell to use MAMP’s mysql executable, which is located in
/Applications/MAMP/Library/bin
. However, I do not recommend exporting that folder, because there are a bunch of other executables there, likelibtool
, that you probably don’t want to be giving priority to over your system installed versions. This issue prevented me from installing a node package recently (libxmljs), as documented here.My solution was to define and export
mysql
andmysqladmin
as functions:I used functions instead of aliases, because aliases don’t get passed to child processes, or at least not in the context of a shell script. The only downside I’ve found is that running
which mysql
andwhich mysqladmin
will no longer return anything, which is a bummer. If you want to check which mysql is being used and make sure everything is copacetic, usemysql --version
instead.Note: @julianromera points out that zsh doesn’t support exporting functions, so in that case, you’re best off using an alias, like
alias mysql='/Applications/MAMP/Library/bin/mysql'
. Just be aware that your aliases might not be available from subshells (like when executing a shell script).In your home folder
/Users/David
for exmaple, you can create a.bash_profile
. In here you can export variables and then add them to your path.Open up the file to edit it in your favourite editor, I use vim.
Then you can add in your path
You want your bit ahead of the
$PATH
as that already includes/usr/bin
which is where the system PHP lives. So the system will always find your MAMP version first.Save this file and then reboot your Terminal and you'll see that you should get your MAMP version.
To test I use
php -v
as OSX Lion uses 5.3.10 and my MAMP is using 5.3.6You can also test using
which php
which will output the path to your current php executable.For XAMPP users you can use this:
And you can check it with: