How To Programming Tech Fixes Technology

Solved – PHP, dyld: Library not loaded

I mistakenly ran brew upgrade on my macOS Catalina without thinking about how it would impact my production development environment during work, and quickly realized I messed up big time.

To fix it, install openssl & icu4c, edit the php 5.6 source (see post for details), and reinstall php 5.6 from source to overwrite.

131 characters

My production environment has to use PHP 5.6.40 because of some legacy plugins that do not exist, or were not installed with a package manager (e.g. composer) because it didn’t exist at the time, and the business has not decided to invest the time to update all the features to use newer versions…and in some cases there are no newer versions.

So after updating my environment, I had to make sure I didn’t get put back on PHP 7.4.x, and was still on PHP 5.6. I was, but it was now broken.

Error Messages

The first error message I got when trying to check the PHP version

tsnMac:~ neotsn$ php -v
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
  Referenced from: /usr/local/bin/php
  Reason: image not found
Abort trap: 6

This is because macOS has its own SSL library installed, and PHP 5.6 requires OpenSSL…and isn’t compatible with OpenSSL 1.1, which is what got installed in the update.

After reinstalling OpenSSL 1.0 from a direct package link, I encountered the next message, which was much more difficult to solve, since icu4c is covered by macOS Data Integrity Protection.

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
  Referenced from: /usr/local/Cellar/php@5.6/5.6.40/bin/php
  Reason: image not found

The Fixes

Thanks to the instructions over in this Github Issue from JParkinson1991, and various other articles and blogs around the internet I’ve pieced together this solution, but his updated comment provided the majority of the answer.

Starting over?

Obviously you’re going to need Homebrew, which you probably already have if you’re here… but in case you wiped your hard disk (as I did) and have to start over…

# Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL"

# Bring in deprecated php versions
brew tap exolnet/homebrew-deprecated

Now you’ll have Homebrew installed and the deprecated PHP versions available to you.

Update these packages

Before you start down the path, make sure the problematic packages (openssl and icu4c) are at the latest versions (and indeed installed).

# Make sure these are at the latest versions
brew install openssl && brew upgrade openssl
brew upgrade icu4c

Patching PHP 5.6

Note: This will soon be fixed

At the time of this writing, there exists a merge request for the php@5.6 package where the following patch will no longer be required. I do not have instructions on what to do once it has been, but presumably this article will never reach your eyeballs if you have the latest version of these eXolnet repositories.

The patch…

If the above merge request is still outstanding, then let’s edit the php@5.6 package…

# Edit php@5.6 to add a patch 
brew edit php@5.6

This will open up the edited file in vim (or at least it did for me). So jump to line 45-48. Look for the def install around there. Right before that line, insert these lines…

# At line 45, before the `def install` command, add these lines
patch do
  url ""
  sha256 "c9715b544ae249c0e76136dfadd9d282237233459694b9e75d0e3e094ab0c993"

Save your changes and exit with an esc press and a :wq.

Reinstall php@5.6 from source

Now that our package is different from what was downloaded, we need to reinstall it from that source…

# Reinstall php@5.6 from the edited source
brew reinstall --build-from-source php@5.6

This will take a minute or two. When it’s done you should be able to do a php -v command to see that there are no more errors and you’re on the correct version.

Run the checkup

Afterward, be sure to run the doctor and cleanup commands to make sure everything is both good, and clean.

# Get a checkup
brew doctor
brew cleanup

Minor Troubleshooting Suggestions

If you happen to see you’re not on the right version of PHP after this, you may have to do a forced overwrite link.

# Only if php -v is not 5.6.x
brew link --overwrite --force php@5.6

If you need to have multiple versions of PHP installed, then you’re going to want sphp installed.

# Install sphp to switch versions 
curl -L > /usr/local/bin/sphp
# Make it executable
chmod +x /usr/local/bin/sphp

Then you’ll be able to switch between them with sphp 5.6 or any other installed versions using their major/minor version numbers.

If you have trouble, you can try dropping a comment here, or onto the linked Github pages where there are better experts than I who may be able to help.

By [[Neo]]

I am a web programmer, system integrator, and photographer. I have been writing code since high school, when I had only a TI-83 calculator. I enjoy getting different systems to talk to each other, coming up with ways to mimic human processes using technology, and explaining how complicated things work.

Of my many blogs, this one is purely about the technology projects, ideas, and solutions that I have come across in my internet travels. It's also the place for technical updates related to my other sites that are part of The-Spot.Network.

3 replies on “Solved – PHP, dyld: Library not loaded”

Thanks, past self… I forgot I wrote this article and unfortunately I ran brew upgrade, broke my php, and then decided to run updates on my blogs and saw this as the last post made.

It looks like asking brew to edit the file opened it up in Atom this time, when I ran the command from my IDE’s terminal instead of the macOS terminal.

However, this time the error is related to a bug in icu4c v68 that got fixed for later versions of php, but not for 5.6, so I have to reinstall an older version of icu4c, which requires a checkout, commit search, and reinstall at that version from that branch. It sucks.

For me I had to
1) Install the Command Line Tools:
xcode-select –install
2) then remove libpsl
brew uninstall libpsl
3)next reinstall php
brew reinstall php
Thats it!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.