mac使用php-version切換PHP版本

來源:互聯網
上載者:User

標籤:bash   lease   this   versions   prefix   直接   升級   多個   bre   

在開發過程中,有時候我們的程式對某個php版本有著極為重要的限制,特別是大型項目。

因此,我們就需要切換多個php版本來滿足我們的需求。

我們使用php-version來達到這個目的。

首先我們先使用brew安裝一個php5.6,為什麼不使用系統原有的php5.6呢?

這個是因為有時候升級系統時,會把內建的php配置給還原,所以我們使用一個新下載的php5.6。

brew install homebrew/php/php56

下載完之後,我們先把php5.6給unlink,不然我們的php7是無法安裝的。會報以下錯誤

Error: Cannot install homebrew/php/php70 because conflicting formulae are 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. You can --force thisinstall, but the build may fail or cause obscure side-effects in theresulting software

這個時候提示我們需要執行一下

brew unlink php56

接著我們就可以下載php7了

homebrew/php/php70

下載完之後,我們就可以下載php-version了

brew install php-version

這個時候你無法直接使用php-version命令,你需要把下面這句放在~/.zshrc或者~/.bashrc的下面

source $(brew --prefix php-version)/php-version.sh && php-version 5

接著

source ~/.zshrc  或者 source ~/.bashrc

現在的話,你執行php-version就會看到有兩個php版本

?  ~  php-version  5.6.31* 7.0.22

帶星號代表著正在使用的是php7.0,只要重啟php,就能成功切換php版本咯

mac使用php-version切換PHP版本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.