因为需要我要在mac上装两个php版本,先前我已经装过php7.4,下面我们逐步安装php8.0


开始安装8.0:
直接运行安装
brew install php@8.0

遇到问题怀疑是仓库太老了,更新一下homebrew ,重新安装
brew update

安装成功了,不过看了下版本好像不能正常打印版本了
报错相关文档,查询了下好像是icu4c 这个依赖版本不一致的问题,后面查了下相关资料操作麻烦,干脆一点全部卸载重装,包括原有的php7.4
现在系统全部的php版本都清空了记得删干净。
安装php7.4

安装7.4失败了,官方不维护了,用下面的命令安装,类似一个历史仓库
bash
# 1. 添加tap formulae
brew tap shivammathur/php
# 2. 安装
brew install shivammathur/php/php@7.4

成功把环境变量加上,然后查看一下版本正常输出
下面安装php8.0


安装成功,把php8同样加入环境变量里,只需要执行php -v即可打印出版本,奇怪怎么一直打印php7.4版本呢
那么我们怎么使用php8呢,找到下面两个文件修改默认名称
bash
#进入的php/bin目录使用mv php php8 把php改成php8
/opt/homebrew/Cellar/php@8.0/8.0.30/bin
#进入的php/sbin目录使用mv php-fpm php-fpm8
/opt/homebrew/Cellar/php@8.0/8.0.30/sbin
然后重新打开一个终端

完事。