Finn
Finn

Reputation: 371

Can't open PHP, dyld: Library not loaded

I am aware there are many other questions related to this error, but I have tried all the answers and nothing worked.

Full error

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

When did the error occur?

Right after updating Ruby to 2.6.3 via RVM.

Whenever I enter "php" into the terminal the error appears.

Steps taken

Versions

When running 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)

Any ideas on how to solve this error?

Upvotes: 13

Views: 13596

Answers (4)

Finn
Finn

Reputation: 371

After having uninstalled and reinstalled every single keg of brew I found the following solution:

  1. Uninstall PHP
  2. Run brew cleanup
  3. Check your /usr/local/opt folder for any folders named php
  4. Delete the folder (in my case it was called '[email protected]')
  5. Open a new terminal window
  6. Run 'brew search php' in the terminal and make sure no php keg is installed.
  7. Simply type 'php -v' in the terminal. For me this showed a version number, indicating that php was (at one point) installed without brew. You can choose to uninstall this version or update it to the newest version.

Conclusion

In my case I believe it was simply that PHP 7.1 was already installed and I installed a 2nd version (7.4) via brew.

The error Referenced from: /usr/local/opt/[email protected]/bin/php was obviously searching for something in this folder and after deleted it, the error stopped.

Upvotes: 9

John
John

Reputation: 358

In my case, the error was

❯ 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)

Uninstall PHP was not sufficient, also needed to remove gd and libavif.

Steps:

brew uninstall php
rm -rf /opt/homebrew/etc/php
brew uninstall gd
brew uninstall libavif
brew install php

Finally, at this point the error went away

❯ php -v
PHP 8.2.10 (cli) (built: Aug 31 2023 18:52:55) (NTS)

Upvotes: 14

maxLeet
maxLeet

Reputation: 1

In my case, i had multiple version of php installed on my macOs, which was later remedies with laradock.

Primary problem:

❯ 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/[email protected]/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)

Also tried

❯ 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

As indicated "Referenced from" a php version was still installed after mutliple attempts of brew uninstall php

Solution:

rm -rf /opt/homebrew/etc/php

After above brew install php without a problem. Hope this helps.

Upvotes: 0

DevonDahon
DevonDahon

Reputation: 8350

I had similar issue which I fixed this way:

brew reinstall php

Upvotes: 19

Related Questions