查看可按照版本:
brew search php
使用brew安装:
brew install php@7.4
但报错:
Error: php@7.4 has been disabled because it is a versioned formula!
这是因为php7.4官方已经不再维护,所以Hombrew将该php版本移出了repository,所以安装不了。
解决方案
从第三方仓库中安装 比如(所有旧版php仓库地址https://github.com/shivammath…)
//将第三方仓库加入brew
brew tap shivammathur/php
//安装PHP
brew install shivammathur/php/php@7.4
替换Mac自带PHP环境并刷新环境变量
Linking /usr/local/Cellar/php@7.4/7.4.29.reinstall... 25 symlinks created.If you need to have this software first in your PATH instead consider running: echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc ``` 3、执行配置
echo ‘export PATH=“/usr/local/opt/php@7.4/bin: P A T H "′ > > / . z s h r c e c h o′ e x p o r t P A T H = " / u s r / l o c a l / o p t / p h p @ 7.4 / s b i n : PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.4/sbin: PATH"′>> /.zshrcecho′exportPATH="/usr/local/opt/php@7.4/sbin:PATH”’ >> ~/.zshrc
``
刷新环境变量
source ~/.zshrc
输出php版本
PHP 7.4.29 (cli) (built: Apr 14 2022 11:48:33) ( NTS )Copyright (c) The PHP GroupZend Engine v3.4.0, Copyright (c) Zend Technologies ```
来源地址:https://blog.csdn.net/lxy4239/article/details/129497198