1. 默认镜像源安装太慢或发生包not found,第一步切换镜像源为阿里云
其他更多的源参考:Mac 下 brew 切换为国内源 - 腾讯云开发者社区-腾讯云
注意:使用了国内的源之后注意命令行的外网vpn代理就不要开启了,防止卡住
# 查看 brew.git 当前源
$ cd "$(brew --repo)" && git remote -v
origin https://github.com/Homebrew/brew.git (fetch)
origin https://github.com/Homebrew/brew.git (push)
# 查看 homebrew-core.git 当前源
$ cd "$(brew --repo homebrew/core)" && git remote -v
origin https://github.com/Homebrew/homebrew-core.git (fetch)
origin https://github.com/Homebrew/homebrew-core.git (push)
# 修改 brew.git 为阿里源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 修改 homebrew-core.git 为阿里源
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
# bash 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 刷新源
$ brew update
2. 安装php
参考:macOS 使用 Homebrew 安装 PHP7.4 并替代系统自带 PHP 教程 - 知乎
# 搜索php
brew search php
# 安装php7.4
brew install php@7.4
# 在PATH中追加php
export PATH="/usr/local/opt/php@7.4/bin:$PATH"