CentOS编译安装php扩展gd

//安装平台:
centos 5.5 x86_64

//软体:
详见安装过程

//安装基础依赖包
>yum -y install gcc gcc-c++ autoconf ncurses

//编译安装zlib
>tar zxvf zlib-1.2.5.tar.gz
>cd zlib-1.2.5
>./configure --prefix=/usr/local/zlib
>make
>make install

//编译安装 libpng
>tar zxvf libpng-1.5.1.tar.gz
>cd libpng-1.5.1
>./configure --prefix=/usr/local/libng
>make
>make install

//编译安装 jpeg
>tar zxvf jpegsrc.v8c.tar.gz
>cd jpeg-8c/
>./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
>make
>make install
>ln -s /usr/local/libjpeg/lib/* /usr/lib/

//编译安装 freetype
>tar zxvf freetype-2.4.4.tar.gz
>cd freetype-2.4.4
>./configure --prefix=/usr/local/freetype
>make
>make install

//编译安装 fontconfig
>tar zxvf fontconfig-2.8.0.tar.gz
>cd fontconfig-2.8.0
>./configure --with-freetype-config=/usr/local/freetype/bin/freetype-config
>make
>make install

//编译安装libxml
>tar zxvf libxml2-2.7.4.tar.gz
>cd libxml2-2.7.4
>./configure --prefix=/usr/local/libxml
>make
>make install

//编译安装libiconv
>tar zxvf libiconv-1.13.1.tar.gz
>cd libiconv-1.13.1/
>./configure --prefix=/usr/local/libiconv
>make
>make install

//编译安装libmcrypt
>tar zxvf libmcrypt-2.5.8.tar.gz
>cd libmcrypt-2.5.8
>./configure --prefix=/usr/local/libmcrypt
>make
>make install

//编译安装gettext
>tar zxvf gettext-0.18.1.1.tar.gz
>cd gettext-0.18.1.1
>./configure
>make
>make install

//编译安装 GD
>tar zxvf gd-2.0.35.tar.gz
>cd gd-2.0.35
>vi gd_png.c
include "/usr/local/libpng/include/png.h"
>./configure --prefix=/usr/local/libgd --with-png=/usr/local/libpng --with-libiconv-prefix=/usr/local/libiconv --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/libjpeg --with-fontconfig=/usr/local/fontconfig/ --enable-m4_pattern_allow
>make
>make install

 

 

 

整合php & gd
  对于php5.4有个bug,在 "gdIOCtx"结构体中没有 "data" 这个成员,解决办法
$vi <gd_dir>/include/gd_io.h
/*
typedef struct gdIOCtx

{
  int (*getC) (struct gdIOCtx *);
  int (*getBuf) (struct gdIOCtx *, void *, int);
  void (*putC) (struct gdIOCtx *, int);
  int (*putBuf) (struct gdIOCtx *, const void *, int);
  int (*seek) (struct gdIOCtx *, const int);
  long (*tell) (struct gdIOCtx *);
  void (*gd_free) (struct gdIOCtx *);
  void (*data);// 新添加这一行
}
*/

  整合php & gd
$ cd <php源文件>/ext/gd
$ /usr/local/php5/bin/phpize //生成configure
$ ./configure --with-gd=/usr/local/gd --with-jpeg-dir=/usr/local/jpeg8d --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype --with-zlib-dir=/usr/local/zlib --with-php-config=/usr/local/php5/bin/php-config
$ make && make install
$ vi /usr/local/php5/apache/php.ini
/*
extension=gd.so //添加这一行
*/
$ apache restart

注:不知道是不是动态扩展gd的原因, 这个时候访问服务器并不能打开网页, 查找apache error_log, 上面写着:
/usr/local/apache//bin/httpd: symbol lookup error: /usr/local/php5/lib/php/extensions/no-debug-zts-20100525/gd.so: undefined symbol: gdJpegGetVersionString

/usr/local/apache//bin/httpd: symbol lookup error: /usr/local/php5/lib/php/extensions/no-debug-zts-20100525/gd.so: undefined symbol: gdPngGetVersionString

在网上找了好长时间, 找不到解决这个问题的办法, 或者这个问题引起的原因, 我想到了一个办法作为临时的解决办法:修改gd.c
$ vi $ cd <php源文件>/ext/gd/gd.c
/*
在这个文件的下面添加
# include <{libpng安装目录}png.h>
# include <{libjpeg安装目录}jpeglib.h>
const char * gdJpegGetVersionString()
{
          switch(JPEG_LIB_VERSION) {
                  case 62:
                          return "6b";
                          break;
                  default:
                          return "unknown";
          }
}

const char * gdPngGetVersionString()
{
         return PNG_LIBPNG_VER_STRING;
}

*/

然后重新整合php & gd, 问题解决,可以生成验证码.

 

 

 

 

转载于:https://www.cnblogs.com/keethebest/archive/2013/06/13/3133906.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值