I'm using Mac High Sierra. I installed PHP (with GMP) using
brew install php72-gmp
Everything installed successfully, per the messages given, but it would seem I still have an old version of PHP 7.1 somewhere on my machine because when I run
localhost:php-7.2.1 davea$ which php
/usr/bin/php
localhost:php-7.2.1 davea$ /usr/bin/php -v
PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
So I'd like to figure out where to put the homebrew version of PHP ahead in my PATH so that that version gets picked up first.
EDIT:
As of 2018 and the latest updates to Brew your php formula names have the following format [email protected]
.
When you run brew info [email protected]
your path should be /usr/local/Cellar/[email protected]/
And there will be a symbolic link to /usr/local/bin/opt/[email protected]/
So in order to change your php installation you just need to run this in terminal:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.bash_profile
or put it manually in your .bash_profile
like this:
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
===========================================================================
The location of your Homebrew installed php should be /usr/local/Cellar/php72
These are the steps you need to do to setup your PHP on macOS:
After you install php with brew run this in terminal:
export PATH="$(brew --prefix homebrew/php/php72)/bin:$PATH"
Then run:
source ~/.bash_profile
To check your current active version of php run this in terminal:
which php
EDIT:
run brew info php72
in console to get all info, hints and caveats for php, it is really useful, for example this comes from brew info:
✩✩✩✩ PHP CLI ✩✩✩✩
If you wish to swap the PHP you use on the command line, you should add the
following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent
configuration file:
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With