[Fixed] Mac OSX - Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php56-imagick/imagick.so'

Red Lina

After removing PHP version 5.4 and then I installed a newer version of PHP (PHP 5.6) via Home Brew:

$ brew rm php54
$ brew install php56

Check version of PHP CLI

$ php -v

I got the following error message showing:

Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php56-imagick/imagick.so' - dlopen(/usr/local/opt/php56-imagick/imagick.so, 9): Library not loaded:

After hours of searching on Google, I finally found the solution solves the issue is to reinstall PHP and all of it modules from source. The command looks like this:

$ brew reinstall php56-imagick --build-from-source

Change the name php56-imagick to the name that matches your installed version of PHP.

The important thing to note from the above command is to pass the option --build-from-source. Also you need to tell Homebrew to reinstall the package not just install. Otherwise, if you already installed the ImageMagick package for PHP then Homebrew will do nothing.

Finally check version of PHP again:

$ php -v
PHP 5.6.6 (cli) (built: Mar 17 2015 13:35:17) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Xdebug v2.2.7, Copyright (c) 2002-2015, by Derick Rethans