mac升级后PHP失败报错Error: [email protected] has been disabled because it is a versioned formula!

  • 各种补救方法皆不可用,开始卸载重装
# 查看服务列表
brew services list
#卸载
brew uninstall [email protected]
#删除配置目录
 rm -rf /usr/local/etc/php/7.3
# 恢复brew
brew doctor
# 重新安装
brew install [email protected]
  • 如果过程中有包下载不下来可以更换源或者开启代理
    打开代理
export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;

  • 终端关闭代理
unset http_proxy
unset https_proxy

  • 安装完毕后的配置信息
==> [email protected]
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so

    
        SetHandler application/x-httpd-php
    

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.4/

[email protected] is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.


To restart [email protected] after an upgrade:
  brew services restart [email protected]
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/[email protected]/sbin/php-fpm --nodaemonize
  • 添加到环境变量中去,变量文件可以在下面文件中添加
    a. /etc/profile
    b. /etc/paths
    c. ~/.bash_profile
    d. ~/.bash_login
    e. ~/.profile
    f. ~/.bashrc

  • 添加完毕,更新文件,让环境变量生效并查看是否生效

zhangguofu@zhangguofudeMacBook-Pro ~ $ vi ~/.bash_profile 
zhangguofu@zhangguofudeMacBook-Pro ~ $ source ./.bash_profile
zhangguofu@zhangguofudeMacBook-Pro ~ $ echo $PATH
  • 执行php -v
zhangguofu@zhangguofudeMacBook-Pro ~ $ php -v
-bash: php: command not found # 呃,没有找到这个文件,我们看看有没有这个目录吧
zhangguofu@zhangguofudeMacBook-Pro [email protected] $ cd /usr/local/opt/
zhangguofu@zhangguofudeMacBook-Pro [email protected] $ ls -al
lrwxr-xr-x    1 zhangguofu  admin    24 Dec 24 14:25 [email protected] -> ../Cellar/[email protected]/7.4.27 # 发现是一个软连接
# 进入真实文件路径查看文件
zhangguofu@zhangguofudeMacBook-Pro opt $ cd ../Cellar/[email protected]/      
zhangguofu@zhangguofudeMacBook-Pro [email protected] $ ls
7.4.27.reinstall
# 发现文件名不是7.4.27 修改文件名
zhangguofu@zhangguofudeMacBook-Pro [email protected] $ mv 7.4.27.reinstall 7.4.27
zhangguofu@zhangguofudeMacBook-Pro [email protected] $ php -v
PHP 7.4.27 (cli) (built: Dec 16 2021 18:14:46) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.27, Copyright (c), by Zend Technologies
  • 安装完毕

你可能感兴趣的:(mac升级后PHP失败报错Error: [email protected] has been disabled because it is a versioned formula!)