
这里作者挂了梯子,所以很流畅!
brew的下载,可参考另外一篇博文~Homebrew 安装与卸载
1、将第三方仓库加入brew
clike
brew tap shivammathur/php

2、安装指定版本的PHP
clike
brew install php@7.4

3、替换Mac自带PHP环境并刷新环境变量

clike
-> % vim ~/.zshrc
将以下内容加入环境变量
clike
echo 'export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/php@7.4/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@7.4/include"
刷新环境变量
clike
source ~/.zshrc
最后,查看php版本
clike
php -v
