PHP can not load Imagick library - PHP Startup: Unable to load dynamic library

PHP can not load Imagick library - PHP Startup: Unable to load dynamic library

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Resolving "Library not loaded" Errors for Imagick on macOS High Sierra

When attempting to load the Imagick extension in PHP, you might encounter a startup error indicating that a specific dynamic library cannot be found. The error message PHP Startup: Unable to load dynamic library ... Reason: image not found is a classic linker failure. It tells us that the .so file trying to initialize has dependencies—specifically shared object files—that the operating system cannot resolve at runtime.

In your specific scenario, the PHP binary is looking for /usr/local/opt/imagemagick/lib/libMagickWand-7.Q16HDRI.5.dylib. The error explicitly states that this file is missing from the expected path. While you have installed ImageMagick via Homebrew and possess the imagick.so extension file, the linker cannot bridge the gap between the extension and its underlying ImageMagick libraries.

Understanding the Dynamic Linker Failure

The core issue here is a mismatch in how the dynamic linker resolves dependencies. When PHP starts, it loads the imagick.so module. This module was compiled against specific versions of ImageMagick libraries (likely the Q16HDRI version). The error message confirms that the file libMagickWand-7.Q16HDRI.5.dylib is not located at /usr/local/opt/imagemagick/lib/.

On macOS, Homebrew often installs libraries in /usr/local/opt/<package>/lib. However, the linker searches for these files based on the paths embedded in the compiled binary or specified in environment variables like DYLD_LIBRARY_PATH. If ImageMagick was installed previously with a different prefix, or if a recent re-installation moved the library files without updating the cache or the search path, the linker fails.

The fact that PHP runs without crashing suggests that the core engine is intact; only the Imagick extension fails to initialize. This results in a Warning during startup, rendering image manipulation functions unavailable until the dependency is resolved.

Diagnosing the Missing Dependency

To fix this, you must verify exactly where Homebrew has installed the ImageMagick libraries and ensure that path is discoverable by the PHP binary. First, locate the actual location of the missing library:

brew list imagemagick --verbose
# Or specifically check for the dylib
ls -la /usr/local/opt/imagemagick/lib/

If the directory /usr/local/opt/imagemagick/lib/libMagickWand-7.Q16HDRI.5.dylib does not exist, but ImageMagick is installed, it is possible that Homebrew placed the files in a non-standard location or that the installation was incomplete. You can also check if the library exists elsewhere:

find /usr/local -name "libMagickWand-7.Q16HDRI.5.dylib" 2>/dev/null

If the file is found at a different path, say /usr/local/lib, you have two primary options to resolve the mismatch.

Option 1: Reinstalling with Correct Dependencies

The most robust solution is often to reinstall ImageMagick via Homebrew while ensuring that all dependencies are linked correctly. Sometimes, simply running brew install imagemagick is insufficient if the library files are not being placed in the standard Homebrew Cellar structure expected by PHP extensions compiled on older systems.

Run the following command to ensure a clean installation:

brew reinstall imagemagick --verbose

After reinstalling, verify that the specific dylib file now exists at /usr/local/opt/imagemagick/lib/. If it does, you may need to clear PHP's internal cache or restart your PHP-FPM service (if running via systemd or supervisord) to force it to reload the extension. For CLI usage, simply closing and reopening the terminal session usually suffices.

Option 2: Modifying Environment Variables

If reinstalling does not move the library to the expected path, you can manually instruct the dynamic linker where to find the libraries by setting the DYLD_LIBRARY_PATH environment variable. This variable overrides the default search paths for dynamic libraries on macOS.

Add the following line to your shell configuration file (e.g., ~/.bash_profile, ~/.zshrc, or ~/.profile) before the PATH export:

export DYLD_LIBRARY_PATH="/usr/local/opt/imagemagick/lib:$DYLD_LIBRARY_PATH"

After updating this file, source it using source ~/.zshrc (or the appropriate shell command). Then, restart your PHP CLI or reload your web server. This forces the dynamic linker to look in the /usr/local/opt/imagemagick/lib/ directory before falling back to system defaults, satisfying the requirement of the imagick.so extension.

A Note on Modern Development Environments

While resolving this specific error is critical for legacy projects running PHP 7.1 on High Sierra, it is worth noting that maintaining older PHP versions and macOS releases introduces significant friction. The combination of PHP 7.1.9 and macOS High Sierra (10.13.6) is quite dated. Modern ImageMagick versions and PHP distributions often rely on newer system libraries or different compilation flags that may not be compatible with this specific stack.

For new development, it is strongly recommended to migrate to a supported version of PHP (8.x) and a modern macOS release. This eliminates the need for manual library path hacking and ensures access to current security patches and extension versions. If you are working within an existing Laravel application or similar framework, ensuring your server environment aligns with the version requirements listed on https://laravelcompany.com can prevent many such low-level configuration headaches in the future.

Final Verification

Once you have either reinstalled ImageMagick to the correct location or updated your DYLD_LIBRARY_PATH, run the following command to confirm the extension loads without warnings:

php -m | grep imagick

If this command returns imagick without any preceding startup warnings, the dynamic library dependency has been successfully resolved, and you can proceed with image manipulation tasks.

Our network