ubuntu 中php不支持gd库的freetype,导致页面验证码无法加载
admin
2023-06-20 13:21:54
0

1、修改源

cp /etc/apt/sources.list /etc/apt/sources.list.bak

vim /etc/apt/sources.list

先删除里面的东西,再将下列写入:

deb http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse

保存后,执行:

apt-get update

2、安装工具

apt-get install wget

apt-get install vim

3、建立测试文件:

在apache访问目录下,建立文件phpinfo.php,写入以下内容:

if(extension_loaded('gd')){

echo 'can use gd
';

foreach(gd_info() as $cate=>$value)

echo "$cate: $value
";

}else

echo 'can not use gd'

?>

在浏览器上访问:http://test.com/phpinfo.php

can use gd

GD Version: bundled (2.0.34 compatible)

FreeType Support:                            #这里冒号后面没有值,说明gd不支持freetype

T1Lib Support:

GIF Read Support: 1

GIF Create Support: 1

JPEG Support: 1

PNG Support: 1

WBMP Support: 1

XPM Support:

XBM Support: 1

JIS-mapped Japanese Font Support:

4、下载相关包

wget http://zlib.net/zlib-1.2.8.tar.gz

wget http://ftp.yzu.edu.tw/nongnu//freetype/freetype-2.6.tar.gz

wget https://github.com/libgd/libgd/releases/download/gd-2.1.1/libgd-2.1.1.tar.gz

wget http://cn2.php.net/distributions/php-5.4.30.tar.gz

wget http://www.ijg.org/files/jpegsrc.v9.tar.gz

wget http://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.21/libpng-1.6.21.tar.gz

5、apt-get -y install autoconf libxml2-dev bzip2 openssl

6、解压并安装

tar -xzvf freetype-2.6.tar.gz

tar -xzvf php-5.4.30.tar.gz

tar -xzvf zlib-1.2.8.tar.gz

tar -xzvf libpng-1.6.21.tar.gz

tar -xzvf jpegsrc.v9.tar.gz

tar -xzvf libgd-2.1.1.tar.gz

cd libpng-1.6.21

./configure --prefix=/usr/local/libpng

make && make install

cd zlib-1.2.8

./configure --prefix=/usr/local/zlib

make && make install

cd freetype-2.6

cd builds/unix/

./configure --prefix=/usr/local/freetype --enable-shared

cd ../..

./configure --prefix=/usr/local/freetype --enable-shared

make && make install

cd jpeg-9

./configure --prefix=/usr/local/jpeg

make && make install

cd libgd-2.1.1

./configure --with-zlib=/usr/local/zlib/ --with-png=/usr/local/libpng/ --with-jpeg=/usr/local/jpeg/ --with-freetype=/usr/local/freetype/

make && make install

7、备份

cp -r php5_4_3 php5_4_3bak

8、建模块链接

cd /usr/lib/

ln -s /usr/lib/x86_64-linux-gnu/libXpm.so .

ln -s /usr/lib/x86_64-linux-gnu/libXpm.a .

ln -s /usr/lib/x86_64-linux-gnu/libXpm.so.4 .

ln -s /usr/lib/x86_64-linux-gnu/libXpm.so.4.11.0 .

ln -s /usr/lib/x86_64-linux-gnu/libssl.so .

ln -s /bin/sed /usr/bin/sed

9、编译php

cd php-5.4.30

./configure --prefix=/home/php/php5_4_3/ --with-config-file-path=/home/php/php5_4_3/etc/ --with-apxs2=/home/apache/2_2_22/apache/bin/apxs --with-gd --with-iconv --with-jpeg-dir=/usr/local/jpeg/ --with-zlib=/usr/local/zlib/ --enable-xml --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbstring=all --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-session --enable-imap --enable-calendar --enable-eaccelerator=shared --enable-wddx --with-freetype-dir=/usr/local/freetype/ --without-pear

make

make install

10、重启apache

可以在页面上重启,但是重启后请确认是否重启成功:可用ps -ef | grep http 结果查看进程时间来确定

如果页面重启不成功,尝试:

cd /home/apache/2_2_22/apache/bin/

apachectl restart

如果有错误,具体处理就行

11、测试

浏览器访问:http://test.com/phpinfo.php

结果为:

can use gd

GD Version: bundled (2.1.0 compatible)

FreeType Support: 1                             #这里有值

FreeType Linkage: with freetype                  #这里有值

T1Lib Support:

GIF Read Support: 1

GIF Create Support: 1

JPEG Support: 1

PNG Support: 1

WBMP Support: 1

XPM Support:

XBM Support: 1

JIS-mapped Japanese Font Support:

12、成功后将phpinfo.php这个文件删除


相关内容

热门资讯

新一代网络与存储模组发布,释放... 来源:市场资讯 (来源:华为计算) 【中国,北京,2026年5月23日】鲲鹏昇腾开发者大会2026(...
网络安全人的2026:AI攻击... HSBC CEO在最近一次采访中说了一句话:"不要和AI对抗——银行正在因为AI裁员,也正在被AI攻...
7名科学家获2026年度邵逸夫... 中新社香港5月27日电 (记者 赵静怡)邵逸夫奖基金会27日在香港公布2026年度邵逸夫奖获奖名单,...
跨越式升级!解析Harmony... 2026年4月20日,华为正式发布了HUAWEI Pura X Max、HUAWEI MateBoo...
甘肃天水5G+智慧物流园开启快... 今年,天水5G+智慧物流园项目投入试运行以来,5G智慧分拣配送中心无人分拣设备运行稳定,日均分拣包裹...
禾电迅取得小型化北斗多频卫星天... 国家知识产权局信息显示,深圳市禾电迅科技有限公司取得一项名为“一种小型化北斗多频卫星天线”的专利,授...
特朗普警告盟友阿曼:不守规矩会... 新华社华盛顿5月27日电(记者黄强 徐剑梅)美国总统特朗普27日在白宫举行的内阁会议上说,霍尔木兹海...
4G DTU模块厂家梳理 工业... 导语:在工业物联网场景中,4G DTU模块作为数据传输的核心设备,其稳定性、兼容性及服务响应能力直接...
原创 美... 5月25日,华为在上海丢出了一颗深水炸弹。 半导体业务部总裁何庭波在IEEE国际电路与系统研讨会上,...
真正该按下暂停键的,不是AI的... 事情发生在一个寻常不过的深夜。 我正坐在电脑前,赶着明天要交的企划案,窗外是连绵不断的春雨。工作堆得...