今天帮一好朋友搭一个lamp环境,搭成之后意外的出现图片验证码显示不出的问题。汗,,晕死了。
记得上次配CACTI时同样碰到png图片不能显示的问题,于是根据cacti的配置方法安装GD及所依赖的相关库,列个清单:
首先安装zlib,freetype,libpng,jpeg 以便于让PHP 支持GD 库
1) 安装zlib
cd /home/software
tar xvf zlib-1.2.5.tar.tar
cd zlib-1.2.5
./configure --prefix=/usr/local/zlib
make
make install
cd ../
2) 安装freetype
cd freetype-2.3.5
./configure --prefix=/usr/local/freetype
make
make install
cd ../
3) 安装linpng
tar xvf libpng-1.4.3.tar.gz
cd libpng-1.4.3
cd scripts/
mv makefile.linux ../makefile
注意,这里的makefile 不是用./configure生成,而是直接从scripts/里复制
cd ..
make
make install
cd /home/software
4) 安装jpeg
tar xvf jpegsrc.v7.tar.gz
cd jpeg-7
mkdir /usr/local/libjpeg/{include,bin,lib,man/man1}
./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
make
make install
注意,这里configure带--enable-shared 参数是为了生成共享库
cd ../
5) 检查libxml版本是否符合php5的要求
#rpm -qa |grep libxml
//版本符合要求,则不需要再安装,否则,需要卸载libxml包,安装更高版本的libxml.
//#rpm -e libxml*
//#cd libxml-2.7.7
//#./configure
//#make
//#make install
//在我的环境中已经存在并符合要求,于是没有安装
6) 安装fontconfig
tar xvf fontconfig-2.8.0.tar.gz
cd fontconfig-2.8.0
./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config
make
make install
cd ../
gettext
tar xvf gettext-0.18.1.1.tar.gz
cd gettext-0.18.1.1
./configure
make && make install
7) 安装GD
cd gd-2.0.35
./configure --prefix=/usr/local/libgd --with-png --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/libjpeg
缺省情况下,GD库编译时并不加入JPEG支持,得修改Makefile文件。
修改Makefile文件,使得:
CFLAGS=-O -DHAVE_XPM -DHAVE_JPEG -DHAVE_LIBTTF
LIBS=-lm -lgd -lpng -lz -ljpeg -lttf -lXpm -lX11
此后,编译并安装:
make
make install
cd ../
8) 编辑 /etc/ld.so.conf
echo "/usr/local/zlib/lib" >> /etc/ld.so.conf
echo "//usr/local/freetype/lib" >> /etc/ld.so.conf
echo "///usr/local/libjpeg/lib" >> /etc/ld.so.conf
echo "//usr/local/libgd/lib" >> /etc/ld.so.conf
ldconfig
9) 安装PHP
tar xvf php-5.2.14.tar.gz
cd php-5.2.14
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd=/usr/local/libgd --enable-gd-native-ttf --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/libjpeg --with-png-dir=/usr --with-zlib-dir=/usr/local/zlib --enable-xml --enable-mbstring --enable-sockets
make && make install
ln -s /usr/local/php/bin/* /usr/local/bin