Homebrew and ImageMagick

WordPress has a wonderful new plugin called Site Health. It does a great job letting you know what issues need to be repaired in order to have a healthy WordPress install.

One issue I had trouble solving was the message I kept getting saying that “imagick” was not available. I found a few links that addressed the issues with older versions of PHP but none that helped complete the update with the current version (which is 7.3.8 at the time of this posting).

First, I’ll go over what setup I currently have. Then, I’ll explain in detail what I did to successfully get Imagick working.

My Setup

I run WordPress 5.2.2 on a Mac. To keep the server up-to-date, I use Homebrew. I’ve used Homebrew to install an updated version of Apache, PHP, MySQL, and various modules:

  • Apache/2.4.41 (Unix)
  • MySQL 8.0.17 Homebrew
  • PHP 7.3.8

Install ImageMagick

Use the following commands to install ImageMagick as requested by WordPress:

brew install imagemagick
brew install pkg-config
pecl install imagick

If all goes well, you should see something similar to this:

Build process completed successfully
Installing '/usr/local/Cellar/php/7.3.8/include/php/ext/imagick/php_imagick_shared.h'
Installing '/usr/local/Cellar/php/7.3.8/pecl/20180731/imagick.so'
install ok: channel://pecl.php.net/imagick-3.4.4
Extension imagick enabled in php.ini

The last line means that the line extension="imagick.so" was added to the top of your php.ini file. Take note of the location of “imagick.so” (above on line 3). Unfortunately, I still received an error message:

Warning: PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/local/lib/php/pecl/20180731/imagick.so (dlopen(/usr/local/lib/php/pecl/20180731/imagick.so, 9): image not found), /usr/local/lib/php/pecl/20180731/imagick.so.so (dlopen(/usr/local/lib/php/pecl/20180731/imagick.so.so, 9): image not found)) in Unknown on line 0

The link I included above (fix for php 7.2) mentions adding an additional *.ini file with this imagick directory listed. However, that did not fix the issue for me. What worked for me was updating the extension location within the php.ini file.

For my install, the php.ini file was here:

/usr/local/etc/php/7.3/php.ini

Go to that directory:

cd /usr/local/etc/php/7.3

Open php.ini:

sudo nano php.ini

Find this line:

extension=imagick.so

Change it to this (copy/paste the imagick.so location from the install confirmation above):

extension="/usr/local/Cellar/php/7.3.8/pecl/20180731/imagick.so"

Save your changes and restart everything:

brew services restart --all
sudo apachectl restart

Check the Install

Lastly, go to Terminal and enter this command to check that imagick is connected to php:

php -m | grep -i magic

The result should be:

imagick

Once I completed these steps, the nag message from within Site Health disappeared! ImageMagick was connected and working as it should.

I hope this works for you. If you need further help, feel free to comment below. Thanks!

Published
Categorized as Server

By Sharon

Hello there! I'm a web developer in Louisville, Kentucky. I started on this career path by purchasing an O’Reilly PHP book from Barnes & Noble in 1999. Since then, my desire to learn as much as I can about web site building and server maintenance has grown. I love technology and what it can do to simplify our lives and make it more interesting all at the same time. Seeing a creative design come to life and bringing it into the web world is my favorite puzzle to solve. My server experience is based around launching WordPress-friendly servers — Linux (Ubuntu and Centos flavors), Apache, MySQL, and PHP. I have worked with various modules, extensions, installs such as ImageMagick, LetsEncrypt, Sass, LESS, and the Homebrew family of extension. My main love has been with PHP, and my CMS of choice has been WordPress since its inception in 2003. I find it flexible, secure, easy to design around, and so customizable. My strengths are in developing from-scratch plugins and themes for the WordPress CMS with a strong background in PHP and MySQL development.

Leave a comment

Your email address will not be published. Required fields are marked *