如何在MAC OS中将PHP一个版本切换到另一个版本?

时间:2017-08-04 03:32:39

标签: php

我在mac中使用自制软件安装了php7.1。但是,当我尝试php -version时,它显示5.5。我该如何切换版本。我找不到php7.1的php instalation目录来设置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

修改

我看到我的php installtion目录下  的 /usr/local/etc/php/7.1 但它只包含php.ini和pear.conf文件。

我试过

导出PATH =“$(brew --prefix homebrew / php / php71)/ bin:$ PATH” 但它并没有改变我的php版本。(我试过php --version,仍然显示5.5)

1 个答案:

答案 0 :(得分:0)

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!