Install PHP’s imagick extension on Mac with Brew

Oh Dear! monitors your entire site, not just the homepage. We crawl and search for broken pages and mixed content, send alerts when your site is down and notify you on expiring SSL certificates.

Start your free 10 day trial! »

Image of Mattias Geniar

Mattias Geniar, October 16, 2019

Follow me on Twitter as @mattiasgeniar

I was setting up a new Mac and ran into this problem again, where a default PHP installation with brew is missing a few important extensions. In this case, I wanted to get the imagick extension loaded.

This guide assumes you have Homebrew installed and you’ve installed PHP with brew install php.

Install Image Magick dependency

First, install imagemagick itself. This is needed to get the source files you’ll use later to compile the PHP extension with.

$ brew install pkg-config imagemagick

This will also install the needed pkg-install dependency.

Compile Imagick PHP extension with pecl

Next up, use pecl to get the PHP extension compiled.

$ pecl install imagick
[...]
install ok: channel://pecl.php.net/imagick-3.4.4
Extension imagick enabled in php.ini

It will also auto-register itself in your php.ini and should now be available.

$ php -m | grep -i magic
imagick

Note: if you run php-fpm, make sure you to restart your daemon to load the latest extension. Use brew services restart php.

Subscribe to my newsletter

Get a weekly-ish update on Linux, open source & webdev called cron.weekly.

Will you help me share this post?

It would mean a lot to me if you could help share this post on social media. 🤗