Skip to content

Instantly share code, notes, and snippets.

@irazasyed
Last active March 4, 2024 15:03
Show Gist options
  • Save irazasyed/5987693 to your computer and use it in GitHub Desktop.
Save irazasyed/5987693 to your computer and use it in GitHub Desktop.
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.

@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

Thank you so much.... very very helpful

@afiaudofia
Copy link

Thanks for this. It worked for me.

@antoniocosentino
Copy link

Worked for me, thanks a lot!

@citrinefan
Copy link

super! thanks a lot!

@phpcontrols
Copy link

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

:) thanks

@anandabayu
Copy link

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

@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

@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

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

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

@stevenworldplay
Copy link

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

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

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

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

@kingozorg
Copy link

kingozorg commented Oct 3, 2022 via email

@psikom
Copy link

psikom commented Dec 4, 2022

It worked perfectly. Thank you

@sidshetty
Copy link

Just what I was looking for. thank you

@mubahood
Copy link

Thank you so much for this!!!

@filmfilmm
Copy link

Thank,It's workk

@kish2011
Copy link

kish2011 commented Mar 4, 2024

Thanks. it works. I think we can put 8.X.X as well

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