'How to switch PHP one version to another version in MAC OS?

I have installed php7.1 using homebrew in mac. But when i try php -version it shows 5.5. How can I switch version. I could not find my php instalation directory for php7.1 to set the path at bash_profile.

#brew install php71
Warning: homebrew/php/php71 7.1.7_19 is already installed

#php --version
PHP 5.5.30 (cli) (built: Oct 23 2015 17:21:45) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

Edit

I see my php installtion directory is under /usr/local/etc/php/7.1 But it contains only php.ini and pear.conf files.

I tried

export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH" But it didn't change my php version.( i tried php --version, still shows 5.5)

php


Solution 1:[1]

I had the same issue, this guide helped me upgrade:

Make sure brew is up to date:

brew update
brew upgrade

(I kinda helped make that update happen! Woo!)

If you’re not already running php7 then you may need:

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php

And then the complicated part:

brew unlink php70 # or  brew unlink php55
brew install php71

And the result?

$ php --version
PHP 7.1.0 (cli) (built: Dec  2 2016 03:30:24) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies

Woohoo!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 meda