今天为ETS网站增长了注册时须要验证码的功能.在本地测试正常,上传到线上以后发现没法正常显示验证码图片 检查发现验证码刷新的动做请求503
了php
这个功能我再其余网站也添加了都没有问题。本地也没问题,那么最大可能就是线上环境致使的问题。 因而检查系统错误日志,发如今日志中有:Image CAPTCHA requires FT fonts support
错误。mysql
因而google
搜索了一下,有人说是GD
扩展没有安装形成的。nginx
但我查看线上phpinfo()
发现GD
扩展有安装。sql
我只好在代码中搜索报错提示Image CAPTCHA requires FT fonts support
curl
查找到报错代码位置 lib\Zend\Captcha\Image.php
460行:socket
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
!!!php-fpm
我想这应该就是问题所在了,个人GD
扩展版本虽然大于2.0.1
但 没有支持freetype
.在phpinfo()
的GD
扩展显示中并无freetype
因而网上搜索教程安装freetype
,并更新GD
扩展测试
freetype
tar -zxvf freetype-2.4.0.tar.gz
freetype
cd freetype-2.4.0 ./configure --prefix=/usr/local/freetype --enable-shared make && make install
也可直接用yum install freetype 直接安装网站
GD
扩展cd /usr/src/php-5.5.29/ext/gd
make clean
/usr/local/php/bin/phpize
./configure --with-php-config=/server/programs/php/bin/php-config --with-zlib-dir --with-png-dir --with-freetype-dir --with-jpeg-dir --with-gd
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
cd /usr/src/php-5.5.29
make clean
./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
make && make install
/etc/init.d/php-fpm restart
最后查看phpinfo()
信息的GD
扩展,检查是否有freetype
库
FreeType Support | enabled |
---|---|
FreeType Linkage | with freetype |
FreeType Version | 2.4.0 |