这里作者挂了梯子,所以很流畅!
brew的下载,可参考另外一篇博文~Homebrew 安装与卸载
1、将第三方仓库加入brew
brew tap shivammathur/php
2、安装指定版本的PHP
brew install php@7.4
3、替换Mac自带PHP环境并刷新环境变量
-> % vim ~/.zshrc
将以下内容加入环境变量
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"
刷新环境变量
source ~/.zshrc
最后,查看php版本
php -v