解决thinkphp5验证码在CentOS7上面无法显示的问题

在做公司项目的过程中,发现在本地的验证码没有问题,在linux上死活加载不出来,对着一张验证码图片看了一天,才发现是php的GD库没安装,折腾了好久,安装GD库也出现了好多问题!

我的php是源码安装的,

先安装 gd 前置库 : freetype ,jpegsrc,libpng。

1.freetype

wget  http://downloads.sourceforge.net/freetype/freetype-2.7.1.tar.bz2

tar jxvf freetype-2.7.1.tar.bz2

-----------------------------------------我是分割线----------------------------------------------------

如果解压的时候出现以下错误,你可以尝试着安装bzip2,因为可能是你解压缩软件没安装

tar (child): lbzip2: Cannot exec: No such file or directory 
tar (child): Error is not recoverable: exiting now 
tar: Child returned status 2 
tar: Error is not recoverable: exiting now

解决方法: yum install bzip2

-----------------------------------------我是分割线----------------------------------------------------

cd freetype-2.7.1

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

make && make install

2.jpegsrc

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

tar zxvf jpegsrc.v9.tar.gz
cd jpeg-9

CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/jpeg

make && make install

3.libpng

wget https://downloads.sourceforge.net/project/libpng/libpng16/1.6.34/libpng-1.6.34.tar.gz

tar zxvf libpng-1.6.34.tar.gz
cd libpng-1.6.34
CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/libpng
make && make install

接下来切换到php源码的ext的gd目录

cd /php-7.1.2/ext/gd

然后运行:/usr/local/bin/phpize

接着运行:./configure --with-php-config=/usr/local/php/bin/php-config --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype

make && make install

最后修改php.ini文件,添加一行 extension=gd.so

然后重启apache:

cd /usr/local/apache/bin/

./apachectl stop

./apachectl start

netstat -tnlp #查看apache是否已经开启

如果出现下面的就表示apache重启成功

至此,GD库安装结束,验证码应该能看到了~

转载于:https://my.oschina.net/zfblog/blog/1837087

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值