I was trying to use Phan, a PHP code analyser, on my Macbook, but it’s requiring PHP 7 cli. I never modified the PHP cli on my machine, mainly because I use MAMP to handle different environments. But here I had no choice. Here is the way I handled it.
Easy trick : use aliases
Yeah, it’s way too easy that way, just create an alias from your command line pointing to a php bin. In my case, I made it point to php7 bin from MAMP.
1 |
alias php='/Applications/MAMP/bin/php/php7.0.0/bin/php' |
Note : you can name it whatever you want. php7 could be a good option too. 😉
To remove the alias :
1 |
unalias php |
To make the changes effective, either close and open your terminal again, or type in
1 |
source ~/.bash_profile |
Cleanest way : using brew
If you have Homebrew installed on your machine, it’s pretty easy to install whatever version of PHP with it. And it’ll take care of every cli bins.
In my case, I had a 5.5 version of PHP already installed, so I need to tell brew to unlink it before installing another one
1 |
brew unlink php55 |
And then, let brew do the dirty work for you
1 |
brew install php70 |
Et voilà !
1 2 3 4 |
$ php -v PHP 7.0.3 (cli) (built: Feb 6 2016 03:16:24) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies |