我先启动CentOS5.1 Linux 可以说如果要配置一台LAMP服务器,都离不开安装gd库,就算自己php开发不涉及到图形方面, 但是如果使用其他一些php开发的工具也会涉及到。
我安装的环境是使用 CentOS5.1 Linux 操作系统.
简单介绍一下gd库: gd库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片。 在网站上GD库通常用来生成缩略图或者用来对图片加水印或者对网站数据生成报表。 也就是有了gd库,我们用php对图片的处理将会得心应手。
等下看我演示如何将 tar.gz 文件 传到虚拟机上的CentOS5.1 操作系统上去。
我用 putty 登陆上CentOS5.1, Linux 的ip是192.168.1.118
通过一个工具 webserver 在window上架设一个简单的web服务器 webserver(运行在windows的web小服务器).7z 下载webserver这个工具
http://127.0.0.1:2000 测试 webserver 是否成功工作 , 看到这个页面表示成功了
192.168.1.107 这是我 window 的ip地址。 最后看我操作
我们先安装ncurses-5.6.tar.gz,安装gd库会用到的
去下载一个ncurses-5.6.tar.gz 也可以下载:ncurses-5.6(安装GD库前需要安装的).7z
把 ncurses-5.6.tar.gz 放入 webserv 目录, 看上去像我现在这样。
然后我们在Linux上用 wget http://192.168.1.107:2000/ncurses-5.6.tar.gz 下载在window的文件
解压操作 tar zxvf ncurses-5.6.tar.gz 进入目录 cd ncurses-5.6 生成 makefile文件,再进一步编译 ./configure --prefix=/usr --with-shared --without-debug 编译,编译时间稍微长些,稍等 make 编译好最后就是安装了 make install
==================================
下面才开始安装 GD库,安装gd库成功与否,与下面的安装顺序有一定的关系 我们就一步步来演示安装, 下面所有用到的文件,可以到 文章最后下载 GD库 打包,集合所有需要的文件,省得大家到处找,浪费不必要的时间
把全部的文件 都放进 webserv 目录下
1:安装zlib2 同样, 在Linux下使用 wget 来下载文件 tar zxvf zlib-1.2.3.tar.gz cd zlib-1.2.3 ./configure --prefix=/usr/local/zlib make make install
---------------------------------
2:安装PNG
tar zxvf libpng-1.2.26.tar.gz cd libpng-1.2.26
cp scripts/makefile.linux ./makefile ./configure --prefix=/usr/local/libpng
make make install ---------------------------------
3:安装ttf ( ttf 是字体的支持 ) tar zxvf freetype-2.3.5.tar.gz cd freetype-2.3.5 ./configure --prefix=/usr/local/freetype
make make install
---------------------------------
4:安装JPEG6 tar zxvf jpegsrc.v6b.tar.gz cd jpeg-6b
mkdir -pv /usr/local/libjpeg/{,bin,lib,include,man/man1,man1} 上面这个命令具体是实现这样的: mkdir: created directory `/usr/local/libjpeg' mkdir: created directory `/usr/local/libjpeg/bin' mkdir: created directory `/usr/local/libjpeg/lib' mkdir: created directory `/usr/local/libjpeg/include' mkdir: created directory `/usr/local/libjpeg/man' mkdir: created directory `/usr/local/libjpeg/man/man1' mkdir: created directory `/usr/local/libjpeg/man1' 可以说是一个小小的bug吧,要我们手动建立这些目录,否则configure时候会说找不到目录。
./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
make make install
---------------------------------
5:安装 libxml2
tar zxvf libxml2-2.6.31.tar.gz cd libxml2-2.6.31 ./configure --prefix=/usr/local/libxml2
make 这一步make 操作 时间相对也会比较长,呵呵
make install
cp xml2-config /usr/bin
---------------------------------
6:安装 libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7
./configure make make install
---------------------------------
7:安装Fontconfig
tar -zxvf fontconfig-2.4.2.tar.gz cd fontconfig-2.4.2
可以看到, 参数比较长, 我建议用记事本的朋友不要选择 自动换行。 看我操作, 自动换行 复制过去执行有时会出错。去掉 自动换行 ./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config
这里显示一个错误信息: checking for LIBXML2... configure: error: Package requirements (libxml-2.0 >= 2.6) were not met:
No package 'libxml-2.0' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix.
Alternatively, you may set the environment variables LIBXML2_CFLAGS and LIBXML2_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.
但是我们在上面其实已经安装上 libxml2 了的,这里只是一个 环境变量没有设置好而已。
解决办法: 确定 /usr/local/libxml2/lib/pkgconfig 目录下有 libxml-2.0.pc
export PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH
再次生成 makefile , 这样就成功了
./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config 好了吧,没有出现那个错误了。
make make install
---------------------------------
8:安装GD库,我们把这一步放在最后面
tar zxvf gd-2.0.35.tar.gz cd gd-2.0.35 ./configure --prefix=/usr/local/libgd --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/libjpeg --with-fontconfig=/usr/local/fontconfig
看到下面的信息, 呵呵 很多都显示支持了 Support for PNG library: yes Support for JPEG library: yes Support for Freetype 2.x library: yes Support for Fontconfig library: yes Support for Xpm library: no Support for pthreads: yes make make install
好了, 到这里为止 安装GD库全部过程演示完了, 这样还是不是很好的感觉出来,等我们下一节视频- 就是把 php5.2.6也装上了,那么才知道 php 支持了 gif jpg png wbmp xml ttf字体
如果大家在跟着视频学习的过程中 遇到什么问题或者有什么建议,欢迎给我们留言
或者给我们点支持。 呵呵
演示就到这里, 还有,我们清理一下东西, 呵呵,看我操作
把这些下载的文件 和 解压的文件全部 删除
使用 rm -rf * ( 请大家小心使用这个命令!后果自负 呵呵 )