需要安装 Xcode
命令行工具和Homebrew
xcode-select --install
检查brew是否已安装:
$ brew --version Homebrew 4.1.17
安装不同 PHP 版本命令
brew install php@7.4 brew install php@8.0
安装后,您可以通过brew中的“链接”和“取消链接”在PHP版本之间切换
#断开链接php8.0版本 brew unlink php@8.0 #链接php8.0版本 brew link php@7.4 --force
命令如下(示例):
$ php -v PHP 8.0.30 (cli) (built: Aug 5 2023 06:27:20) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.30, Copyright (c) Zend Technologies with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies $ brew unlink php@8.0 Unlinking /usr/local/Cellar/php@8.0/8.0.30... 229 symlinks removed. $ php -v bash: /usr/local/bin/php: No such file or directory $ brew link php@7.4 --force Linking /usr/local/Cellar/php@7.4/7.4.33_4... 219 symlinks created. If you need to have this software first in your PATH instead consider running: echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc $ php -v PHP 7.4.33 (cli) (built: Sep 1 2023 04:09:59) ( NTS ) Copyright (c) The PHP Group
可以组合brew unlink并brew link在任何已安装的版本之间进行交换
以上就是在macOS上进行多个 PHP 版本之间切换的实现方法的详细内容,更多关于macOS上多个 PHP 版本切换的资料请关注插件窝其它相关文章!