mac PHP安装imageMagic扩展

1. 安装:ImageMagick:
命令:brew install ImageMagick
这种方式安装下来的imageMagic,不缺少东西,报错较少。安装之后的位置:/usr/local/Cellar/imagemagick/

2. 安装php扩展imagick
下载:wget https://pecl.php.net/get/imagick-3.4.3.tgz
解压:sudo tar -zxvf imagick-3.4.3
安装:

cd imagick-3.4.3
sudo /usr/bin/phpize
export PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/7.0.8-12_1/lib/pkgconfig
sudo ./configure --with-php-config=/usr/bin/php-config --with-imagick=/usr/local/Cellar/imagemagick/7.0.8-12_1
sudo make
sudo make install

安装环境的报错
(1)pcre.h文件找不到

/usr/include/php/ext/pcre/php_pcre.h:29:10: fatal error: 'pcre.h' file not found
#include "pcre.h"
         ^
1 error generated.
make: *** [swoole.lo] Error 1

解决方式:brew install pcre

(2)Operation not permitted, no-debug-non-zts

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20131226/
cp: /usr/lib/php/extensions/no-debug-non-zts-20131226/#INST@12567#: Operation not permitted
make: *** [install-modules] Error 1

原因:
原来是OSX 10.11 El Capitan(或更高)新添加了一个新的安全机制叫系统完整性保护System Integrity Protection (SIP),所以对于目录
/System
/sbin
/usr
不包含(/usr/local/)
仅仅供系统使用,其它用户或者程序无法直接使用,而我们的/usr/lib/php/extensions/刚好在受保护范围内

解决方式:禁掉SIP保护机制,步骤是:

重启系统
按住Command + R   (重新亮屏之后就开始按,象征地按几秒再松开,出现苹果标志,ok)
菜单“实用工具” ==>> “终端” ==>> 输入csrutil disable;执行后会输出:Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
再次重启系统
禁止掉SIP后,就可以顺利的安装了,当然装完了以后你可以重新打开SIP,方法同上,只是命令是csrutil enable

最后,在php.ini中加入扩展:

extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20160303"
extension=imagick.so
原文地址:https://www.cnblogs.com/rxbook/p/11379192.html