LAMP攻略: 重新编译PHP安装扩展,GD库安装与配置

LAMP攻略: 重新编译PHP安装扩展,GD库安装与配置

在上一篇 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
*
*********************************************/

我已经把需要的源码包下载到了 /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库安装完成。下一篇我们谈谈如何用phpize来安装php扩展。
如履薄冰
顶楼主,牛哄哄
顶楼主的帖子。受益匪浅
楼主辛苦了  让我们这些菜鸟少走很多弯路啊   请继续更新
非常感谢你!原来我不知从何下手,看了你的贴,然后一步一步跟着做,我装成功了,我真的非常感谢你! 你是第一的,教导有方。

sdfsdf

arfsadf
/usr/local/download/php-5.2.9/ext/gd/gd.c:4148: undefined reference to `gdImageCopyResized'
ext/gd/.libs/gd.o: In function `zif_imagecopymergegray':
/usr/local/download/php-5.2.9/ext/gd/gd.c:4104: undefined reference to `gdImageCopyMergeGray'
ext/gd/.libs/gd.o: In function `zif_imagecopymerge':
/usr/local/download/php-5.2.9/ext/gd/gd.c:4068: undefined reference to `gdImageCopyMerge'
ext/gd/.libs/gd.o: In function `zif_imagecopy':
/usr/local/download/php-5.2.9/ext/gd/gd.c:4031: undefined reference to `gdImageCopy'
ext/gd/.libs/gd.o: In function `php_imagechar':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3950: undefined reference to `gdImageChar'
ext/gd/.libs/gd.o: In function `php_gdimagecharup':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3890: undefined reference to `gdImageSetPixel'
ext/gd/.libs/gd.o: In function `php_imagechar':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3943: undefined reference to `gdImageChar'
/usr/local/download/php-5.2.9/ext/gd/gd.c:3957: undefined reference to `gdImageCharUp'
ext/gd/.libs/gd.o: In function `zif_imagecolordeallocate':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3224: undefined reference to `gdImageColorDeallocate'
ext/gd/.libs/gd.o: In function `zif_imagecolorclosesthwb':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3194: undefined reference to `gdImageColorClosestHWB'
ext/gd/.libs/gd.o: In function `zif_imagecolorclosest':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3172: undefined reference to `gdImageColorClosest'
ext/gd/.libs/gd.o: In function `zif_imagecolorat':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3131: undefined reference to `gdImageBoundsSafe'
/usr/local/download/php-5.2.9/ext/gd/gd.c:3139: undefined reference to `gdImageBoundsSafe'
ext/gd/.libs/gd.o: In function `zif_imagecolorallocate':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3085: undefined reference to `gdImageColorAllocate'
ext/gd/.libs/gd.o: In function `_php_image_output':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2926: undefined reference to `gdImageTrueColorToPalette'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2909: undefined reference to `gdImageWBMP'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2851: undefined reference to `gdImageWBMP'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2866: undefined reference to `gdImageTrueColorToPalette'
ext/gd/.libs/gd.o: In function `zif_imagegd2':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3043: undefined reference to `gdImageGd2'
ext/gd/.libs/gd.o: In function `zif_imagegd':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3034: undefined reference to `gdImageGd'
ext/gd/.libs/gd.o: In function `_php_image_create_from':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2642: undefined reference to `gdNewDynamicCtxEx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2686: undefined reference to `gdImageCreateFromJpeg'
ext/gd/.libs/gd.o: In function `zif_imagecreatefromgd2part':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2794: undefined reference to `gdImageCreateFromGd2PartCtx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2794: undefined reference to `gdImageCreateFromGd2Part'
ext/gd/.libs/gd.o: In function `zif_imagecreatefromgd2':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2786: undefined reference to `gdImageCreateFromGd2Ctx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2786: undefined reference to `gdImageCreateFromGd2'
ext/gd/.libs/gd.o: In function `zif_imagecreatefromgd':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2777: undefined reference to `gdImageCreateFromGdCtx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2777: undefined reference to `gdImageCreateFromGd'
ext/gd/.libs/gd.o: In function `zif_imagecreatefromwbmp':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2768: undefined reference to `gdImageCreateFromWBMPCtx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2768: undefined reference to `gdImageCreateFromWBMP'
ext/gd/.libs/gd.o: In function `zif_imagecreatefrompng':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2738: undefined reference to `gdImageCreateFromPngCtx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2738: undefined reference to `gdImageCreateFromPng'
ext/gd/.libs/gd.o: In function `zif_imagecreatefromjpeg':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2728: undefined reference to `gdImageCreateFromJpegCtx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2728: undefined reference to `gdImageCreateFromJpeg'
ext/gd/.libs/gd.o: In function `zif_imagecreatefromgif':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2718: undefined reference to `gdImageCreateFromGifCtx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2718: undefined reference to `gdImageCreateFromGif'
ext/gd/.libs/gd.o: In function `zif_imagecreatefromstring':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2559: undefined reference to `gdImageCreateFromGd2Ctx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2523: undefined reference to `gdImageCreateFromJpegCtx'
ext/gd/.libs/gd.o: In function `_php_image_type':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2438: undefined reference to `gdNewDynamicCtxEx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2440: undefined reference to `gdGetC'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2440: undefined reference to `getmbi'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2440: undefined reference to `gdGetC'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2440: undefined reference to `skipheader'
ext/gd/.libs/gd.o: In function `zif_imagecreatefromstring':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2541: undefined reference to `gdImageCreateFromGifCtx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2532: undefined reference to `gdImageCreateFromPngCtx'
/usr/local/download/php-5.2.9/ext/gd/gd.c:2550: undefined reference to `gdImageCreateFromWBMPCtx'
ext/gd/.libs/gd.o: In function `zif_imagecopyresampled':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2123: undefined reference to `gdImageCopyResampled'
ext/gd/.libs/gd.o: In function `zif_imagecolorexactalpha':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2086: undefined reference to `gdImageColorExactAlpha'
ext/gd/.libs/gd.o: In function `zif_imagecreate':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2372: undefined reference to `gdImageCreate'
ext/gd/.libs/gd.o: In function `zif_imagecolorclosestalpha':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2064: undefined reference to `gdImageColorClosestAlpha'
ext/gd/.libs/gd.o: In function `zif_imagecolorresolvealpha':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2042: undefined reference to `gdImageColorResolveAlpha'
ext/gd/.libs/gd.o: In function `zif_imagesavealpha':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1971: undefined reference to `gdImageSaveAlpha'
ext/gd/.libs/gd.o: In function `zif_imagealphablending':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1950: undefined reference to `gdImageAlphaBlending'
ext/gd/.libs/gd.o: In function `zif_imagefilledarc':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1930: undefined reference to `gdImageFilledArc'
ext/gd/.libs/gd.o: In function `zif_imagefilledellipse':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1891: undefined reference to `gdImageFilledEllipse'
ext/gd/.libs/gd.o: In function `zif_imagesetthickness':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1866: undefined reference to `gdImageSetThickness'
ext/gd/.libs/gd.o: In function `zif_imagetruecolortopalette':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1805: undefined reference to `gdImageTrueColorToPalette'
ext/gd/.libs/gd.o: In function `zif_imagecreatetruecolor':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1758: undefined reference to `gdImageCreateTrueColor'
ext/gd/.libs/gd.o: In function `zif_imagesetstyle':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1728: undefined reference to `gdImageSetStyle'
ext/gd/.libs/gd.o: In function `_php_image_output_ctx':
/usr/local/download/php-5.2.9/ext/gd/gd_ctx.c:102: undefined reference to `gdNewFileCtx'
ext/gd/.libs/gd.o: In function `zif_imagewbmp':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3022: undefined reference to `gdImageWBMPCtx'
ext/gd/.libs/gd.o: In function `zif_imagejpeg':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3008: undefined reference to `gdImageJpegCtx'
ext/gd/.libs/gd.o: In function `zif_imagepng':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2994: undefined reference to `gdImagePngCtxEx'
ext/gd/.libs/gd.o: In function `zif_imagegif':
/usr/local/download/php-5.2.9/ext/gd/gd.c:2980: undefined reference to `gdImageGifCtx'
ext/gd/.libs/gd.o: In function `zif_imagerectangle':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3494: undefined reference to `gdImageRectangle'
ext/gd/.libs/gd.o: In function `zif_imagedashedline':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3470: undefined reference to `gdImageDashedLine'
ext/gd/.libs/gd.o: In function `zif_imageline':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3445: undefined reference to `gdImageLine'
ext/gd/.libs/gd.o: In function `zif_imagesetpixel':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3414: undefined reference to `gdImageSetPixel'
ext/gd/.libs/gd.o: In function `zif_imagegammacorrect':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3374: undefined reference to `gdImageGetPixel'
/usr/local/download/php-5.2.9/ext/gd/gd.c:3375: undefined reference to `gdImageSetPixel'
ext/gd/.libs/gd.o: In function `zif_imagecolorexact':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3271: undefined reference to `gdImageColorExact'
ext/gd/.libs/gd.o: In function `zif_imagecolorresolve':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3250: undefined reference to `gdImageColorResolve'
ext/gd/.libs/gd.o: In function `zif_imageellipse':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3582: undefined reference to `gdImageArc'
ext/gd/.libs/gd.o: In function `zif_imagearc':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3555: undefined reference to `gdImageArc'
ext/gd/.libs/gd.o: In function `zif_imagefilledrectangle':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3518: undefined reference to `gdImageFilledRectangle'
ext/gd/.libs/gd.o: In function `zif_imagecolortransparent':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3677: undefined reference to `gdImageColorTransparent'
ext/gd/.libs/gd.o: In function `zif_imagefill':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3629: undefined reference to `gdImageFill'
ext/gd/.libs/gd.o: In function `zif_imagefilltoborder':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3607: undefined reference to `gdImageFillToBorder'
ext/gd/.libs/gd.o: In function `php_imagepolygon':
/usr/local/download/php-5.2.9/ext/gd/gd.c:3773: undefined reference to `gdImageFilledPolygon'
/usr/local/download/php-5.2.9/ext/gd/gd.c:3775: undefined reference to `gdImagePolygon'
ext/gd/.libs/gd.o: In function `php_free_gd_image':
/usr/local/download/php-5.2.9/ext/gd/gd.c:1201: undefined reference to `gdImageDestroy'
ext/gd/.libs/gd.o: In function `_php_image_bw_convert':
/usr/local/download/php-5.2.9/ext/gd/gd.c:4908: undefined reference to `gdImageWBMPCtx'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1


make php的时候出现以上错误 请问如何解决?

回复 1# 我不是鱼 的帖子

多谢楼主无私的分享和细心讲解...
谢谢您,让我对如何安装GD库安装,更有头绪了 ^^
楼主,想请问下,您有安装及使用过GBROWSE吗?
我想安装及使GBRWOSE,但似乎遇到很多的error
想请问您是否也有用过及安装GBRWOSE的经验,能分享?
我使用的是ia64 GNU/Linux以及Red Hat Enterprise Linux Server release 5.2...
嘿嘿,按照楼主的说法,安装完毕,中间虽然有几个error(机器环境不同),但是也顺利解决了,来这里大力感谢楼主一番,谢谢你的无私奉献。