无法打开PHP,dyld:库未加载

13

我知道与这个错误相关的问题很多,但我尝试了所有答案,都没有起作用。

完整错误信息

dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /usr/local/opt/php@7.1/bin/php
Reason: image not found
Abort trap: 6

错误发生时间?

在通过 RVM 更新 Ruby 到 2.6.3 后立即出现。

每当我在终端输入“php”时,错误就会出现。

采取的步骤

  • 基本步骤:重新启动 MacBook,打开新的终端窗口。
  • 卸载/重新安装:Node、Openssl、libpng、Ruby
  • 更新/升级:brew
  • 取消链接/链接:libidn、autoconf
  • 通过 chown -R /usr/local 赋予自己所有权限
  • OpenSSL: $sudo rm /usr/bin/openssl,brew reinstall openssl@1.1
  • Brew cleanup
  • 重新安装 PHP

版本

  • Mac OS Mojave 10.14.6

  • PHP 7.4

  • Ruby 2.6.3p62
  • RVM 1.29.9

运行 Brew Doctor 时

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew-provided
script of the same name. We found the following "config" scripts:
  /opt/local/bin/python2.7-config
  /opt/local/bin/curl-config
  /opt/local/bin/ncursesw6-config
  /opt/local/bin/pcre-config
  /opt/local/bin/ncurses6-config
  /opt/local/bin/pcap-config

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected header files:
(here it posts all the /usr/local/include/node files, but the list exceeds character limitations)

有没有解决此错误的想法?

4个回答

16

我遇到了类似的问题,我是这样解决的:

brew reinstall php

也对我有用! - jkndrkn
2
如果你没有使用最新的PHP,那么请执行以下命令:brew reinstall php@7.4 - Zymawy

13
在我的情况下,错误是
❯ php -v
dyld[24982]: Library not loaded: /opt/homebrew/opt/libavif/lib/libavif.15.dylib
  Referenced from: <87C1A268-34E4-396F-8BBC-D5591064E333> /opt/homebrew/Cellar/gd/2.3.3_5/lib/libgd.3.dylib
  Reason: tried: '/opt/homebrew/opt/libavif/lib/libavif.15.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/libavif/lib/libavif.15.dylib' (no such file), '/opt/homebrew/opt/libavif/lib/libavif.15.dylib' (no such file), '/usr/local/lib/libavif.15.dylib' (no such file), '/usr/lib/libavif.15.dylib' (no such file, not in dyld cache), '/opt/homebrew/Cellar/libavif/1.0.1/lib/libavif.15.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/libavif/1.0.1/lib/libavif.15.dylib' (no such file), '/opt/homebrew/Cellar/libavif/1.0.1/lib/libavif.15.dylib' (no such file), '/usr/local/lib/libavif.15.dylib' (no such file), '/usr/lib/libavif.15.dylib' (no such file, not in dyld cache)

卸载PHP是不够的,还需要删除gd和libavif。
步骤:
brew uninstall php
rm -rf /opt/homebrew/etc/php
brew uninstall gd
brew uninstall libavif
brew install php

终于,在这个时候错误消失了。
❯ php -v
PHP 8.2.10 (cli) (built: Aug 31 2023 18:52:55) (NTS)

这在我的 macOS Monterey 上有效。谢谢! - undefined
谢谢这个,对我也起作用了。有一点要注意:确保你检查一个新的标签页/终端实例。在那之前,我一直得到/usr/local/opt/php@7.4/bin/php: No such file or directory的错误提示。 - undefined
请注意,如果您安装了多个PHP版本,使用brew uninstall gd命令将无法生效。您需要使用force选项或者删除所有的PHP版本(稍后可以重新安装它们)。 - undefined
这对我在MacOS Sonoma上有效。 - undefined

9

我将回答自己的问题,以便其他可能遇到类似问题的人

在卸载和重新安装每一个brew keg之后,我找到了以下解决方案:

  1. 卸载PHP
  2. 运行brew cleanup
  3. 检查您的/usr/local/opt文件夹是否有名为php的文件夹
  4. 删除该文件夹(在我的情况下它被称为“php@7.1”)
  5. 打开一个新的终端窗口
  6. 在终端中运行“brew search php”,确保没有安装任何php keg。
  7. 简单地在终端中键入“php -v”。对我来说,这显示了一个版本号,表明php曾经被安装过。您可以选择卸载此版本或将其更新为最新版本。

结论

在我的情况下,我认为问题很简单,即已经安装了PHP 7.1,并通过brew安装了第二个版本(7.4)。

错误'Referenced from: /usr/local/opt/php@7.1/bin/php'显然正在搜索此文件夹中的某些内容,在删除它后,错误停止了。


1
这非常有帮助!我只想补充一点,在我的情况下,我只需要brew uninstall php@5.6,因为某种原因它在/usr/local/opt/文件夹中。一旦完成这个步骤,一切都很顺利。 - cybertoast

0
在我的情况下,我在我的macOS上安装了多个版本的php,后来使用laradock解决了这个问题。
主要问题:
❯ php -v
dyld[62395]: Library not loaded: /opt/homebrew/opt/icu4c/lib/libicuio.70.dylib
  Referenced from: <31116583-6CB3-3C7B-AD46-52FF1431267E> /opt/homebrew/Cellar/php@7.4/7.4.30/bin/php
  Reason: tried: '/opt/homebrew/opt/icu4c/lib/libicuio.70.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/icu4c/lib/libicuio.70.dylib' (no such file), '/opt/homebrew/opt/icu4c/lib/libicuio.70.dylib' (no such file), '/usr/local/lib/libicuio.70.dylib' (no such file), '/usr/lib/libicuio.70.dylib' (no such file, not in dyld cache), '/opt/homebrew/Cellar/icu4c/72.1/lib/libicuio.70.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/icu4c/72.1/lib/libicuio.70.dylib' (no such file), '/opt/homebrew/Cellar/icu4c/72.1/lib/libicuio.70.dylib' (no such file), '/usr/local/lib/libicuio.70.dylib' (no such file), '/usr/lib/libicuio.70.dylib' (no such file, not in dyld cache)

也尝试过

❯ brew uninstall php
Warning: Calling plist_options is deprecated! Use service.require_root instead.
Please report this issue to the mongodb/brew tap (not Homebrew/brew or Homebrew/core), or even better, submit a PR to fix it:
  /opt/homebrew/Library/Taps/mongodb/homebrew-brew/Formula/mongodb-community.rb:55

如所示,“Referenced from”在多次尝试brew uninstall php后仍安装了php版本。

解决方案:

rm -rf /opt/homebrew/etc/php

在上述brew install php没有问题之后。 希望这可以帮到你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接