Apple M1 上使用 Homebrew 的 PHP CLI

esk*_*imo 4 php macos

我已按照本指南在基于 M1 的 Mac 上安装 Homebrew。

之后我跑了

brew install php@7.4
Run Code Online (Sandbox Code Playgroud)

至此PHP安装成功。

如果我现在跑步

brew upgrade php
Run Code Online (Sandbox Code Playgroud)

我明白了

Error: php not installed
Run Code Online (Sandbox Code Playgroud)

我想要实现的是更新 macOS 附带的 PHP,这是7.3.22当我运行php -v.

如何使用 Homebrew 更新 PHP?我知道我需要在 my 中添加一些内容PATH来指向较新的 PHP 版本?鉴于这是一台新机器,我实际上没有文件.bash_profile,只有一个.zshrc(我正在使用 ZSH,我假设将使用该文件并且我不需要一个.bash_profile?)

cee*_*yoz 7

不建议升级系统自带的PHP,但也没有必要。

brew link可用于决定使用哪个PHP。brew link php@7.4应该可以解决问题;这也可以用于切换 PHP 版本,即将brew link php@8.0您切换到该版本,同时保持两个版本均已安装并直接可用。