Install PHP’s imagick extension on Mac with Brew

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile 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.

Permission denied errors?

You may get failed to open stream: Permission denied errors when trying to perform a pecl install. It shouldn’t happen, because Homebrew by default installs everything in local folders, but in case you do get that error you can prefix the commands with sudo like this.

$ sudo pecl install imagick


Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.