今天爲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 |