在上一篇 LAMP攻略: LAMP环境搭建,Linux下Apache,MySQL,PHP安装与配置 中大家是不是总觉得漏了点什么东西呢?对,那就是GD库。这是我们最常用的模块之一。Linux下得GD库安装要比windows麻烦很多。本配置是在
CentOS-5.3
php-5.2.9
的扩展GD库安装。安装用到的源码:
gd-2.0.35
freetype-2.2.1
libpng-1.2.12
jpegsrc.v6b
可以直接点击到下载页面下载。
如果你安装linux系统时选择了安装 X 软件开发。那么很可能这些库已经在你系统安装上。至于怎么查询是否已经安装和卸载,参考上一篇 LAMP攻略: LAMP环境搭建,Linux下Apache,MySQL,PHP安装与配置
这个配置也基本适用于相应的red hat as 5或fedora版本中的配置

/*********************************************
*
* 作 者: 我不是鱼
* LAMP中文网: http://www.lampchina.net
* PHP爱好者站: http://www.phpfans.net
* Email: deng5765@163.com
* 博 客:  http://www.lampchina.net/blog
*
*********************************************/

我已经把需要的源码包下载到了 /usr/local/src 下了。
cd /usr/local/src
进入源码包目录,然后用ls列出用到的源码包,
ls | grep -E ‘jpeg|png|gd|free’
如图

先安装 freetype。
解压
tar -zxvf freetype-2.2.1.tar.gz

进入解压的目录
cd freetype-2.2.1

安装到/usr/local/freetype
./configure –prefix=/usr/local/freetype

编译并安装
make && make install

安装完后再安装png
执行
cd ../
回到源码包目录
解压
tar -zxvf libpng-1.2.12.tar.gz

执行
cd libpng-1.2.12
进入解压目录
配置,编译并安装
./configure && make && make install

安装完毕再安装jpeg
执行
cd ../
回到源码包目录
解压
tar -zxvf jpegsrc.v6b.tar.gz

进入解压目录
cd jpeg-6b
因为jpeg安装不能自动创建文件夹,所以要先创建文件夹,否则会找不到文件夹而编译失败。
分别创建,如图
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/include
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/man
mkdir /usr/local/jpeg6/man/man1

执行
./configure –prefix=/usr/local/jpeg6 –enable-shared –enable-static

编译并安装
make && make install

安装完毕最后安装gd
执行
cd ../
回到源码包目录
解压
tar -zxvf gd-2.0.35.tar.gz

执行
cd gd-2.0.35
进入解压包
执行
./configure –prefix=/usr/local/gb –with-jpeg –with-png –with-freetype

执行
make

执行
make install

好了,GD安装完毕,现在用重新编译php的方法安装gd库扩展。
上一章说到的lamp环境配置,我的php是解压在 /usr/local/src/php-5.2.9
可以直接进入这个目录
cd /usr/local/src/php-5.2.9
然后重新配置php,配置是想保留原有配置的基础上新增gd库,
原有的配置可能很多人安装就忘了,没关系,这个可以在phpinfo()的Configure Command 中看到
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/lib –with-apxs2=/usr/local/httpd/bin/apxs –with-mysql –with-zlib –enable-mbstring –enable-xml –with-gd –with-jpeg-dir=/usr/local/jpeg6 –with-png-dir –with-freetype-dir=/usr/local/freetype

configure成功的话会看到 Thank you for using PHP 的字样
执行
make

执行
make install

安装完成后重启apache
/usr/local/httpd/bin/apachectl -k restart

打开phpinfo页面应该就可以在Configure Command 及下面看到gd的信息

至此,PHP扩展GD库安装完成。

http://hi.baidu.com/xf0825/blog/item/eda9d6952e070940d1135e8e.html

Published in Linux, PHP
Tags: , , ,

No Responses to “LAMP攻略: 重新编译PHP安装扩展,GD库安装与配置”

Leave a Reply

请输入算式结果(看不清请点击图片)
(必须)