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.
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.
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/Cellaremail@example.com/5.6.40/bin/php Reason: image not found
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.
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 https://raw.githubusercontent.com/Homebrew/install/master/install)" # 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 (
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 firstname.lastname@example.org 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.
If the above merge request is still outstanding, then let’s edit the
# Edit email@example.com to add a patch brew edit firstname.lastname@example.org
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 "https://raw.githubusercontent.com/opencomputeproject/Rack-Manager/master/Contrib-Inspur/openbmc/meta-openembedded/meta-oe/recipes-devtools/php/php/0001-PHP-5.6-LibSSL-1.1-compatibility.patch" sha256 "c9715b544ae249c0e76136dfadd9d282237233459694b9e75d0e3e094ab0c993" end
Save your changes and exit with an
esc press and a
email@example.com from source
Now that our package is different from what was downloaded, we need to reinstall it from that source…
# Reinstall firstname.lastname@example.org from the edited source brew reinstall --build-from-source email@example.com
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
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 firstname.lastname@example.org
If you need to have multiple versions of PHP installed, then you’re going to want
# Install sphp to switch versions curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw > /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.