Skip to content

Instantly share code, notes, and snippets.

@irazasyed
Last active August 6, 2024 16:43
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.

@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

@chansnock
Copy link

thank's so much, i follow your instruction and very well result

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