Mac switch PHP version with php-version

Source: Internet
Author: User
Tags install php install homebrew

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.