使用 brew 将 PHP 更新到 7.4 macOS Catalina

Update PHP to 7.4 macOS Catalina with brew

我尝试使用 brew 在 macOS Catalina 上将我的 PHP 版本更新为 7.4

我做到了brew install php@7.4

如果我检查我的版本 php -v,我仍然看到旧版本 PHP 7.3.11?

我需要做什么?

更新:

brew doctor 之后我得到:

Warning: Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin. Consider setting the PATH for example like so: echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.profile

尝试:

brew update
brew upgrade php
php -v
brew services start php

brew services restart php

如果您使用 apache 服务器:

sudo apachectl restart

如果你使用 ngnix

sudo nginx -s reload

编辑:

brew unlink php@7.3
brew link php@7.4

你可以找到我对 的类似答案。

  • brew install php@7.4
  • brew link --force --overwrite php@7.4
  • brew services start php@7.4
  • export PATH="/usr/local/opt/php@7.4/bin:$PATH"
  • export PATH="/usr/local/opt/php@7.4/sbin:$PATH"

我最近遇到了这个问题,直到我运行:

这里所有的建议都没有用
xcode-select --install

然后 运行 我之前尝试的命令并且错误停止了,对于我来说是 php

dyld:库未加载:/usr/local/opt/openldap/lib/libldap-2.4.2.dylib 参考自:/usr/local/opt/php@7.4/bin/php 原因:找不到图片 zsh: 中止 php -v

使用 MacOS 的终端。不要在 vscode.

中使用终端
  1. 我通过以下方式移动到目录:cd /usr/local
  2. 通过以下方式查找文件位置:find /usr/local/ -name libphp7.so。 (然后获取文件位置:/usr/local//Cellar/php@7.4/7.4.23/lib/httpd/modules/libphp7。所以。我复制这个。)
  3. 我通过以下方式打开文件:sudo vim /etc/apache2/httpd.conf
  4. 通过以下方式查找行:/libphp7.so
  5. 取消注释行并通过以下方式更新行:LoadModule php7_module /usr/local//Cellar/php@7.4/7.4.23/lib/httpd/modules/libphp7.so
  6. 通过以下方式重新启动 apache:sudo apachectl restart
  7. 通过访问 http:///localhost/phpinfo.php
  8. 验证 PHP

如果有人想根据系统需求将 php 从最新的 8.1.2 降级到 7.4,请使用自制程序尝试以下命令: 安装 PHP 7.4 :

brew install php@7.4
brew services restart php
brew unlink php@8.1
brew link php@7.4
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

或者

export PATH="/usr/local/opt/php@7.4/bin:$PATH"
export PATH="/usr/local/opt/php@7.4/sbin:$PATH"