查看可按照版本:

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、执行配置

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">> /.zshrcechoexportPATH="/usr/local/opt/php@7.4/sbin:PATH”’ >> ~/.zshrc
``

4、刷新环境变量
source ~/.zshrc

5、 输出php版本

PHP 7.4.29 (cli) (built: Apr 14 2022 11:48:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies ```

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部