In the development process, sometimes our program has very important limitations on a PHP version, especially for large projects.
Therefore, we need to switch multiple versions of PHP to meet our needs.
We use Php-version to achieve this goal.
First, we first use brew to install a php5.6, why not use the original php5.6 of the system?
This is because sometimes when upgrading the system, the PHP is configured to restore, so we use a new download php5.6.
Brew Install HOMEBREW/PHP/PHP56
After downloading, we first give php5.6 to unlink, otherwise our PHP7 is unable to install. will report the following error
Error:cannot install HOMEBREW/PHP/PHP70 because conflicting formulae is installed. Php56:because different PHP versions install the same binaries. Please ' Brew unlink php56 ' before continuing. Unlinking removes a formula ' s symlinks from/usr/local. You canlink the formula again after the install finishes. Can--force Thisinstall, but the same build may fail or cause obscure side-effects in theresulting software
This time, we need to do something.
Brew Unlink Php56
Then we'll be able to download PHP7.
Homebrew/php/php70
Once downloaded, we can download the php-version.
Brew Install Php-version
You cannot use the php-version command directly at this time, you need to put the following sentence under the ~/.ZSHRC or ~/.BASHRC
SOURCE $ (Brew--prefix php-version)/php-version.sh && php-version 5
Then
SOURCE ~/.ZSHRC or source ~/.BASHRC
Now if you execute php-version you'll see there are two PHP versions
? ~ php-version 5.6.31* 7.0.22
With an asterisk indicates that you are using the php7.0, as long as you restart PHP, you can successfully switch PHP version
Mac switch PHP version with php-version