[已解决]Mac PHP yii CException GD with freetype or imagemagick PHP extensions are required

使用Mac开发PHP,使用Yii framework,但是发现后台使用YII自带的验证码时,无法正常使用,出现:

CException GD with freetype or imagemagick PHP extensions are required

error

缺少gd库,需要重新编译安装php,其过程十分辛苦,经过摸索发现使用brew安装比较方便。

首先安装freetype,jpeg,libpng,gd,zlib

解决的办法如下:

brew rm freetype jpeg libpng gd zlib
brew install freetype jpeg libpng gd zlib
#先删除之前的再安装新的

然后创建链接

brew link --overwrite libpng freetype jpeg
#注意添加overwrite,否则可能会提示冲突

接着安装php

brew install php56
#我这里安装的5.6,你也可以安装其他版本

安装完成之后你应该会看到以下提示信息

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module    /usr/local/opt/php54/libexec/apache2/libphp5.so

The php.ini file can be found in:
    /usr/local/etc/php/5.4/php.ini

✩✩✩✩ PEAR ✩✩✩✩

If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
    chmod -R ug+w /usr/local/Cellar/php54/5.4.33/lib/php
    pear config-set php_ini /usr/local/etc/php/5.4/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:

      PATH="/usr/local/bin:$PATH"

PHP54 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.

✩✩✩✩ PHP CLI ✩✩✩✩

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:

      export PATH="$(brew --prefix homebrew/php/php54)/bin:$PATH"

To have launchd start php54 at login:
    ln -sfv /usr/local/opt/php54/*.plist ~/Library/LaunchAgents
Then to load php54 now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php54.plist

环境变量、设置开机启动什么的在此就不作说明了,我们需要做的是将原apache里的libphp5.so路径替换成/usr/local/opt/php56/libexec/apache2/libphp5.so

sudo vim /etc/apache2/httpd.conf
sudo apachectl restart

输出phpinfo(),gd库已安装成功,大功告成!

phpinfo参考:

http://www.fieryrain.com/blog/mac_php_gd

http://www.xiaoxiangzi.com/Programme/PHP/2599.html

文章的脚注信息由WordPress的wp-posturl插件自动生成



|2|left
打赏

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: