Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikelyons/fd417ae7e388fa1fa94e to your computer and use it in GitHub Desktop.
Save mikelyons/fd417ae7e388fa1fa94e to your computer and use it in GitHub Desktop.

##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.

###Install Composer Package Management

Now you can fire the command to install the composer:

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

After the download & installation is done, You can add this alias to your .bash_profile or .profile file to get composer to work globally instead of php /usr/bin/composer.phar command.

alias composer="php /usr/bin/composer.phar"

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.

@bragin2951
Copy link

@moonvader, use sudo, like this
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin

@dameer
Copy link

dameer commented Oct 24, 2017

-bash: /Users/qurac/.bash_profile: line 1: unexpected EOF while looking for matching `"'
-bash: /Users/qurac/.bash_profile: line 3: syntax error: unexpected end of file

Any ideas what's going on?

@dameer
Copy link

dameer commented Oct 24, 2017

Got it! There was an extra double quote at the beginning of the file. However both

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin

...end up with an error message saying: "The installation directory "/usr/bin" is not writable"

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