Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instructions on how to change preinstalled Mac OS X PHP to MAMP's PHP Installation and then install Composer Package Management

Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management


Instructions to Change PHP Installation


First, Lets find out what version of PHP we're running (To find out if it's the default version).

To do that, Within the terminal, Fire this command:

which php

This should output the path to the default PHP install which comes preinstalled by Mac OS X, by default it has to be (Assuming you've not changed it before):

/usr/bin/php

Now, We just need to swap this over to the PHP that is installed with MAMP, which is located at /Applications/MAMP/bin/php/php5.4.10/bin (MAMP 2.1.3)

To do this, We need to edit the .bash_profile and add the MAMP version of PHP to the PATH variable.

Follow these simple steps:


  1. Within the Terminal, run vim ~/.bash_profile

  2. Type i and then paste the following at the top of the file:

     export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
    
  3. Hit ESC, Type :wq, and hit Enter

  4. In Terminal, run source ~/.bash_profile

  5. In Terminal, type in which php again and look for the updated string. If everything was successful, It should output the new path to MAMP PHP install.

  6. In case it doesn't output the correct path, try closing the terminal window (exit fully) and open again, it should apply the changes (Restart in short).

Install Composer Package Management


Now you can fire the command to install the composer globally (So you can access it from anywhere):

$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

You can verify your installation worked by typing the following command within the Terminal:

composer

It'll show you the current version and a list of commands you can use if the installation was successful.

@preciousgeorge
Copy link

preciousgeorge commented Mar 13, 2018

@Narayanareddy96 your solution was the only one that worked. Thanks man.

@madhurikulkarni
Copy link

madhurikulkarni commented Mar 13, 2018

@irazasyed.. That was the right and a very simple solution. Solved a lot of errors including the intl missing extension with MAMP PRO.

@TopCheff
Copy link

TopCheff commented Mar 16, 2018

puedo tener más de una versión php instalada en MAMP y poder seleccionar la que más me convenga?

@omadoyeabraham
Copy link

omadoyeabraham commented Mar 26, 2018

Years down the line, and this just saved me a whole lot of "googling". Thanks a lot

@ajvillegas
Copy link

ajvillegas commented Jul 19, 2018

It worked perfectly. Thank you!

@Phongveth
Copy link

Phongveth commented Jul 29, 2018

Thank your very much @Narayanareddy96 , Worked for me , when to did follwing those steps

@pimkle
Copy link

pimkle commented Aug 7, 2018

Thank you so much!

@vivekarora
Copy link

vivekarora commented Sep 10, 2018

Thank you so much.... very very helpful

@afiaudofia
Copy link

afiaudofia commented Sep 17, 2018

Thanks for this. It worked for me.

@antoniocosentino
Copy link

antoniocosentino commented Oct 26, 2018

Worked for me, thanks a lot!

@citrinefan
Copy link

citrinefan commented Feb 7, 2019

super! thanks a lot!

@phpcontrols
Copy link

phpcontrols commented Mar 7, 2019

I had a similar issue, turns out the order in which I was setting the PATH var was the problem:
ok:
export PATH="/usr/local/php5/bin:/usr/bin:$PATH"

not ok:
export PATH="/usr/bin:/usr/local/php5/bin:$PATH"
I had a php bin in both folders...

So make sure that the folder with the correct php version is placed first in the PATH variable

That was it. Thanks!

@RaShellM
Copy link

RaShellM commented Jul 19, 2019

:) thanks

@anandabayu
Copy link

anandabayu commented Aug 28, 2019

Thanks, this helped so much.

@Luismij
Copy link

Luismij commented Oct 5, 2019

Thank you this helped me so much

@zhe1ka
Copy link

zhe1ka commented Nov 18, 2019

thanks

@saulojmc
Copy link

saulojmc commented Apr 1, 2020

thanks my friend

@Rizzeol
Copy link

Rizzeol commented May 24, 2020

very helpful. solved after 2 days of struggle. many thanks.

@djeffkanda
Copy link

djeffkanda commented Jul 25, 2020

@JonWalkerTN are you using oh-my-zsh by any chance? That's what I'm using, and instead of editing ~/.bash_profile, edit your ~/.zshrc instead, and add the exact same lines. Then run source ~/.zshrc. That solved the issue for me.

many weeks of struggle. Thanks

@great2gether
Copy link

great2gether commented Aug 11, 2020

@JonWalkerTN are you using oh-my-zsh by any chance? That's what I'm using, and instead of editing ~/.bash_profile, edit your ~/.zshrc instead, and add the exact same lines. Then run source ~/.zshrc. That solved the issue for me.

@zhiachong Thank you so much :-) It felt like a big achievement to change that link hahaha. Had a good laugh when t finally worked after trying for quite some time.

@Hayyi123SM
Copy link

Hayyi123SM commented Oct 6, 2020

terimakasih banyak / thank you so much.... finally solved during this week

@marielLatellaBarros
Copy link

marielLatellaBarros commented Nov 22, 2020

THANK YOU so much! I've been struggling with this for YEARS :0)

@DouweGalaxy
Copy link

DouweGalaxy commented Jan 1, 2021

brew install composer - after installing brew.sh - is also working nowadays.

@stevenworldplay
Copy link

stevenworldplay commented Mar 30, 2021

thx. big help

@awesome-urch
Copy link

awesome-urch commented Apr 22, 2021

Thank you!

After running
echo $PATH
I get this:
/Applications/XAMPP/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Is it okay?

Because I still get
/usr/bin/php
after running
which php

Please help me

@Mathias-Wa-Mucani
Copy link

Mathias-Wa-Mucani commented Nov 18, 2021

Hello guys,
Can someone here tell me how to make my Mac stop pointing to MAMP composer and php. Have uninstalled MAMP and added the default php and composer to path but every time I do composer something..... or php something..... I get an error -bash: /Applications/MAMP/bin/php/composer: No such file or directory yet when I do which composer, I get /usr/local/bin/composer. Thanks in advance......

@vietnt-uet
Copy link

vietnt-uet commented Dec 30, 2021

You save my day!

@Ayman1970
Copy link

Ayman1970 commented Jan 15, 2022

After several tries, I still get /usr/bin/php like other here, and my php ver is running on MAMP is 7.4.21 ver and also I could run 8.0.8 ver.
but when I run composer installing command, it gives me this message:
-bash: /Applications/MAMP/bin/php/php7.4.16/bin/php: No such file or directory
how to solve this problem, please.

@elvis-onobo
Copy link

elvis-onobo commented Jun 3, 2022

After 2 days of hell, you just saved me. Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment