Magento 添加验证码,请求503,系统日志报错:Image CAPTCHA requires FT fonts support

今天为ETS网站增加了注册时需要验证码的功能.在本地测试正常,上传到线上之后发现无法正常显示验证码图片 检查发现验证码刷新的动作请求503

这个功能我再其他网站也添加了都没有问题。本地也没问题,那么最大可能就是线上环境导致的问题。 于是检查系统错误日志,发现在日志中有:Image CAPTCHA requires FT fonts support 错误。

于是google 搜索了一下,有人说是GD扩展没有安装造成的。

但我查看线上phpinfo()发现GD扩展有安装。

我只好在代码中搜索报错提示Image CAPTCHA requires FT fonts support

查找到报错代码位置 lib\Zend\Captcha\Image.php 460行:

protected function _generateImage($id, $word)
    {
        if (!extension_loaded("gd")) {
            #require_once 'Zend/Captcha/Exception.php';
            throw new Zend_Captcha_Exception("Image CAPTCHA requires GD extension");
        }

        if (!function_exists("imagepng")) {
            #require_once 'Zend/Captcha/Exception.php';
            throw new Zend_Captcha_Exception("Image CAPTCHA requires PNG support");
        }

        if (!function_exists("imageftbbox")) {
            #require_once 'Zend/Captcha/Exception.php';
            throw new Zend_Captcha_Exception("Image CAPTCHA requires FT fonts support");
        }
        .........

可查看到代码报错条件是找不到 imageftbbox 方法。 在php官网查看imageftbbox方法在注释中发现了重点:

Note: 此函数需要 GD 2.0.1 或更高版本(推荐 2.0.28 及更高版本)。
Note: 此函数仅在 PHP 编译时加入 freetype 支持时有效(--with-freetype-dir=DIR )。

这个函数需要GD扩展版本不低于2.0.1 并且需要编译加入freetype!!!

我想这应该就是问题所在了,我的GD扩展版本虽然大于2.0.1 但 没有支持freetype.在phpinfo()GD扩展显示中并没有freetype 于是网上搜索教程安装freetype,并更新GD扩展

安装freetype

  1. 下载freetype-2.4.0.tar.gz
  2. 解压 freetype-2.4.0.tar.gz:
    tar -zxvf freetype-2.4.0.tar.gz
    
  3. 编译安装freetype
    cd freetype-2.4.0
    ./configure --prefix=/usr/local/freetype --enable-shared
    make && make install
    

也可直接用yum install freetype 直接安装

重新编译安装GD扩展

  1. 进入php源码安装目录的扩展文件夹
    cd /usr/src/php-5.5.29/ext/gd
    
  2. 执行make清除原有安装记录
    make clean
    
  3. /usr/local/php/bin/phpize
  4. 重写编译配置
    ./configure --with-php-config=/server/programs/php/bin/php-config --with-zlib-dir --with-png-dir --with-freetype-dir --with-jpeg-dir --with-gd
    
  5. make && make install

开启扩展

  • vi /usr/local/php/lib/php.ini
  • 添加 extension=gd.so

重启服务

/etc/init.d/nginx restart
/etc/init.d/php-fpm restart

问题来了

我的php环境,最开始编译安装时已启用了GD扩展,但不支持freetype,现在希望在不重新安装php的情况下,使其支持freetype

我尝试用phpize重新编译GD库扩展生成gd.so但在php.ini中加入extension=gd.so后重启php,会报错PHP Warning: Module 'gd' already loaded in Unknown on line 0

所以在php.ini中添加启用GD扩展是不行的.

原因是编译安装php时启用的扩展,属于静态扩展,如需改动,只能重新编译安装php

但安装完成php后,通过phpize安装的动态扩展,是可以通过重新编译安装进行改动,不需要重新编译安装php

所以我这种情况还是只能重新编译PHP

重新编译PHP

  1. cd /usr/src/php-5.5.29
  2. make clean
  3. 添加上freetype配置参数
./configure --prefix=/usr/local/php --enable-fpm --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --enable-pdo --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip  --with-jpeg-dir=/usr/local/jpeg  --with-png-dir=/usr/local/png --with-mcrypt=/usr/local/libmcrypt  --with-freetype-dir=/usr/local/freetype
  1. make && make install
  2. /etc/init.d/php-fpm restart

最后查看phpinfo()信息的GD扩展,检查是否有freetype

FreeType Supportenabled
FreeType Linkagewith freetype
FreeType Version2.4.0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值