Find MAMP's installed PHP version(s) you want to use the PHP CLI for:
$ ls -l /Applications/MAMP/bin/php/
- 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
- 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
- Save and exit the editor & reload your
.bash_profile
$ source ~/.bash_profile
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
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
thanks !