macOS 上安装 PHP 扩展 imagick
在 macOS 上安装 Lychee 的时候遇到报错,提示我缺少 ext-imagick
扩展。
于是直接用 pecl install imagick
安装,结果报错:
checking for pkg-config... /opt/homebrew/bin/pkg-config
checking ImageMagick MagickWand API configuration program... checking Testing /usr/local/bin/MagickWand-config... Doesn't exist
checking Testing /usr/bin/MagickWand-config... Doesn't exist
checking Testing /usr/sbin/bin/MagickWand-config... Doesn't exist
checking Testing /opt/bin/MagickWand-config... Doesn't exist
checking Testing /opt/local/bin/MagickWand-config... Doesn't exist
checking Testing /opt/homebrew/bin/MagickWand-config... Doesn't exist
configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.
ERROR: `/private/tmp/pear/temp/imagick/configure --with-php-config=/opt/homebrew/opt/php/bin/php-config --with-imagick' failed
根据报错信息 ImageMagick MagickWand API configuration program
,pecl 没有找到 MagickWand
相关的配置目录,这个应该是 imagick 的底层依赖的库。
根据 brew 的提示信息,找到了 imagemagick
这个包,尝试安装:
brew install imagemagick
经过漫长的等待(挂代理会快一点),终于安装好了,再次执行 pcel install imagick
,安装成功。
$ pecl install imagick
downloading imagick-3.7.0.tgz ...
Starting to download imagick-3.7.0.tgz (360,138 bytes)
.........................................................................done: 360,138 bytes
33 source files, building
running: phpize
Configuring for:
PHP Api Version: 20230831
Zend Module Api No: 20230831
Zend Extension Api No: 420230831
Please provide the prefix of ImageMagick installation [autodetect] :
building in /private/tmp/pear/temp/pear-build-tonyZfuRG8/imagick-3.7.0
...
Build process completed successfully
Installing '/opt/homebrew/Cellar/php/8.3.13/include/php/ext/imagick/php_imagick_shared.h'
Installing '/opt/homebrew/Cellar/php/8.3.13/pecl/20230831/imagick.so'
install ok: channel://pecl.php.net/imagick-3.7.0
Extension imagick enabled in php.ini
执行 php -m | grep imagick
果然看到 imagick 扩展了,问题解决。
$ php -m | grep imagick
imagick
本来使用 docker 会更方便一点,但本地服务我不喜欢再跑一个 docker,太费电。