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