Introduction: When PHP Stops Being Friends with Homebrew
\n\nHave you ever encountered a situation where everything worked perfectly, and then — bam! — your beloved PHP script throws an error that makes your hair stand on end? If you're a macOS developer and recently installed Node.js via Homebrew, you've probably seen this ominous message:
\n\ndyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib\n Referenced from: /usr/local/bin/php\n Reason: image not found\n\nDon't panic! This isn't the end of the world, just a version conflict of the ICU4C library (International Components for Unicode for C). This situation is so common that this question has gathered thousands of views on Stack Overflow. Today we'll figure out why this happens, and more importantly, how to fix it once and for all.
\n\nWhy does the libicui18n.62.dylib error occur?
\n\nLet's break down the mechanics. ICU4C is a library for Unicode support that PHP uses for internationalization (functions like intl, mbstring, and others). When you install PHP via Homebrew, it binds to a specific version of ICU4C that was current at the time of installation.
The problem arises when you install (or update) Node.js via Brew. Node.js also depends on ICU4C, and Brew may update this library to a new version, removing the old one. As a result, PHP is left with a "dead link" to the file libicui18n.62.dylib, which no longer exists. Hence the error:
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib\n\n
Essentially, this is a classic dependency conflict. But the good news is: there is a solution, and it's quite simple.
\n\nSolutions: From Simple to Reliable
\n\nMethod 1: Relinking ICU4C (Quick Fix)
\n\nThe fastest way is to "remind" PHP where the library now resides. Homebrew stores the current version of ICU4C in a different location, but we can create a symbolic link.
\n\n- \n
- First, find out which version of ICU4C is currently installed: \n
brew list --versions icu4c\n\nYou'll see something like icu4c 72.1 (the version number may differ).
- \n
- Now let's create the directory that PHP is looking for and make a symlink: \n
sudo mkdir -p /usr/local/opt/icu4c/lib\nsudo ln -s /usr/local/Cellar/icu4c/72.1/lib/libicui18n.dylib /usr/local/opt/icu4c/lib/libicui18n.62.dylib\n\nImportant: Replace 72.1 with your version of ICU4C. If the version is 73.0, the command would look like this:
sudo ln -s /usr/local/Cellar/icu4c/73.0/lib/libicui18n.dylib /usr/local/opt/icu4c/lib/libicui18n.62.dylib\n\nCheck if PHP works:
\n\nphp -v\n\nIf you see the PHP version without errors — hooray, you've won! But this is a temporary solution. The link will break again with the next ICU4C update.
\n\nMethod 2: Reinstalling PHP via Brew (Recommended)
\n\nA more proper approach is to force PHP to rebuild with the current version of ICU4C. This will take a bit more time but will solve the problem at its root.
\n\n- \n
- First, uninstall the current version of PHP (if it exists): \n
brew uninstall php\n\n- \n
- Then reinstall PHP, explicitly specifying that it should use the current version of ICU4C: \n
brew install php\n\nHomebrew will automatically pull the latest version of ICU4C and rebuild PHP with the correct links. After installation, check:
\n\nphp -v\nphp -m | grep intl\n\nThe intl module should be in the list. If not — you may need to enable it manually in php.ini, but Brew usually does this automatically.