Skip to content

Instantly share code, notes, and snippets.

@oliveratgithub
Created January 4, 2019 08:44
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save oliveratgithub/73bb1add9df20b243807c4b0ab3da81b to your computer and use it in GitHub Desktop.
Save oliveratgithub/73bb1add9df20b243807c4b0ab3da81b to your computer and use it in GitHub Desktop.
Configure the PHP CLI in macOS to use MAMP PHP binaries

Pre-requisites

Find MAMP's installed PHP version(s) you want to use the PHP CLI for:

$ ls -l /Applications/MAMP/bin/php/

Configure PHP CLI in macOS to use MAMP's PHP

  1. First, open your local user's .bash_profile in edit mode, in order to add aliases for accessing the PHP CLI locally
$ pico ~/.bash_profile
  1. Then add any alias to any of MAMP's PHP binaries and your preferred command to access each of them:
alias php5=/Applications/MAMP/bin/php/php5.6.37/bin/php
alias php7=/Applications/MAMP/bin/php/php7.2.8/bin/php
  1. Save and exit the editor & reload your .bash_profile
$ source ~/.bash_profile

Alternative: changing the default php shell command to a MAMP PHP binary

If you just want to have the php command by default using a MAMP PHP binary – instead of the macOS one, update your .bash_profile as follows:

PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php7.2.8/bin:$PATH

Check if everything works as expected

Use e.g. the Version info to check if your alias or PATH changes work as expected:

$ php5 -v
    PHP 5.6.37 (cli) (built: Aug 28 2018 16:24:00) 
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
        with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
$ php7 -v
    PHP 7.2.8 (cli) (built: Aug 28 2018 16:32:29) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Credits

@vossiermaxime
Copy link

thanks !

@suyashdixit
Copy link

After 3 days, finally, my code ran because of this! Thanks.

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