php56-imagick
and other PHP extensions used to be available in the Homebrew/php
tap, but they have been deprecated. The standard way to install PHP extension is to use pecl
, for example:
pecl install imagick
Installing Extensions for Specific Version of PHP
The formula php56-imagick
assumes you need the extension for PHP 5.6. Add PHP 5.6's installation directory into your PATH
so that you are using the correct version of pecl
.
$ PATH=/usr/local/opt/php@5.6/bin:/usr/local/opt/php@5.6/sbin:$PATH pecl install imagick
downloading imagick-3.4.3.tgz ...
Starting to download imagick-3.4.3.tgz (245,410 bytes)
...................................................done: 245,410 bytes
19 source files, building
running: phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
...
...
...
Build process completed successfully
Installing '/usr/local/Cellar/php@5.6/5.6.35_1/include/php/ext/imagick/php_imagick_shared.h'
Installing '/usr/local/Cellar/php@5.6/5.6.35_1/pecl/20131226/imagick.so'
install ok: channel://pecl.php.net/imagick-3.4.3
Extension imagick enabled in php.ini
Extension Installation Error
During my extension installation process, I encountered this error
ERROR: failed to mkdir /usr/local/Cellar/php@7.1/7.1.16_1/pecl/20160303
Which is due to the missing /usr/local/lib/php/pecl
directory. This might be because I have been using PHP 5.x before the release of PHP 7, hence the newer installation does not create the directory. In any case, creating the directory solved this problem
mkdir /usr/local/lib/php/pecl
Compiled Extension Directory
Note that every version of PHP (installed via Homebrew) is located at /usr/local/lib/php/pecl
$ ls -ld /usr/local/Cellar/php@5.6/5.6.35_1/pecl
lrwxr-xr-x 1 hanxue admin 23 Apr 25 2018 /usr/local/Cellar/php@5.6/5.6.35_1/pecl -> /usr/local/lib/php/pecl
Each PHP version will have their own extension directory
$ ls /usr/local/lib/php/pecl/20131226/
imagick.so
php.ini Extension Configuration
pecl
helpfully add the line
extension="imagick.so"
to the top of php.ini
, but `extension_dir is unset. Set it to the correct value
extension_dir = "/usr/local/lib/php/pecl/20131226"
Finally, remember to reload or restart your web server!