随着php版本的升级,如果官方不维护的php版本,brew不在支持安装,比如安装php7.4会提示disabled。这样只能用其他源安装php7.4了。
查看可按照版本:
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
2、替换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、刷新环境变量
source ~/.zshrc
4、 输出php版本
PHP 7.4.33 (cli) (built: Apr 26 2023 19:13:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
文章评论