php image magic,mac下,PHP安装imageMagic扩展(踩坑记录)-Go语言中文社区

背景

使用yii2框架的时候,加载验证码时候,出现报错:

Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required.

环境使用的是mac自带的php环境,缺少了ImageMagic扩展

扩展安装(网上通用的方法)

1. 安装:ImageMagick:

下载:sudo curl -O ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz

解压:sudo tar -zxvf ImageMagick.tar.gz

安装:

cd ImageMagick-7.0.7-22/

sudo ./configure --prefix=/usr/local/ImageMagick

sudo make

sudo make install

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

sudo ./configure --with-php-config=/usr/bin/php-config --with-imagick=/usr/local/ImageMagick

sudo make

sudo make install

3. 最后再在php.ini中写入extension即可

安装踩坑

安装下来发现中间有各种坑:

1.未安装m4 和autoconf工具,会报错如下:

$ sudo /usr/bin/phpize

Configuring for:

PHP Api Version:         20160303

Zend Module Api No:      20160303

Zend Extension Api No:   320160303

Cannot find autoconf. Please check your autoconf installation and the

$PHP_AUTOCONF environment variable. Then, rerun this script.

解决办法:当然是安装m4、autoconf工具

brew install m4

brew install autoconf

2.ImageMagick-devel缺少报错

error: not found. Please provide a path to MagickWand-config or Wand-config program

使用 brew install ImageMagick-devel,安装不成功,放弃治疗,最后放弃该方法安装扩展。

扩展安装(自己发现的方法)

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

安装环境的报错

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

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

重新其中apache,搞定:

php image magic,mac下,PHP安装imageMagic扩展(踩坑记录)-Go语言中文社区_第1张图片

你可能感兴趣的:(php,image,magic)