不從新編譯PHP文件的狀況下php GD庫擴展庫的編譯安裝(centos)

gd-2.0.33.tar.gz http://www.boutell.com/gd/
jpegsrc.v6b.tar.gz http://www.ijg.org/
libpng-1.2.7.tar.tar http://sourceforge.net/projects/libpng/
zlib-1.2.2.tar.gz http://sourceforge.net/projects/zlib/ php

freetype-2.1.9.tar.gzhttp://sourceforge.net/projects/freetype/web

 

一、安裝 zlib 
wget ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/zlib-1.2.3.tar.gz 
tar -zxf zlib-1.2.3.tar.gz 
cd zlib-1.2.3 
./configure --prefix=/usr/local/zlib 
make 
make install 
 
二、安裝 jpeg 
wget ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/jpeg.tar.gz
安裝前先建立jpeg安裝文件所需(以下)目錄,防止提示相似「沒法建立通常文件‘/usr/local/jpeg/***’: 沒有那個文件或目錄" 的錯誤
mkdir /usr/local/jpeg
mkdir  /usr/local/jpeg/bin 
mkdir  /usr/local/jpeg/lib 
mkdir  /usr/local/jpeg/include 
mkdir  /usr/local/jpeg/man 
mkdir  /usr/local/jpeg/man1 
mkdir  /usr/local/jpeg/man/man1 
tar -zxf jpeg.tar.gz 
cd jpeg-6b 
./configure --prefix=/usr/local/jpeg --enable-shared --enable-static 
make 
make install 
 
安裝完成提示: 
Libraries have been installed in: 
/usr/local/jpeg6/lib

 

三、安裝 libpng apache

wget ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/libpng-1.2.16.tar.gz 
tar -zxf libpng-1.2.16.tar.gz 
cd libpng-1.2.16 
./configure --prefix=/usr/local/libpng 
make 
make install

四、安裝 freetype 
wget http://download.savannah.nongnu.org/releases/freetype/freetype-2.3.4.tar.gz 
tar -zxf freetype-2.3.4.tar.gz 
cd freetype-2.3.4 
mkdir -p /usr/local/freetype 
./configure --prefix=/usr/local/freetype 
make 
make install

五、安裝 GD 
wget ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/gd-2.0.33.tar.gz 
tar -zxf gd-2.0.33.tar.gz 
cd gd-2.0.33 
mkdir -p /usr/local/gd2
./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/
make 
make install
(若是出錯見下文)
六、集成PHP GD擴展 到PHP裏
切換到PHP源碼包
若是已經安裝 php,建議經過追加編譯安裝

進入「[php解壓目錄]/ext/gd」目錄,執行以下命令: 
[php安裝目錄]/bin/phpize 
Java代碼  
./configure --with-php-config=[php安裝目錄]/bin/php-config --with-jpeg=[jpeg-6b安裝目錄] --with-png=[libpng安裝目錄] --with-freetype=[freetype安裝目錄] --with-zlib=[zlib安裝目錄] --with-gd=[gd安裝目錄] 
(若是出現未知配置項--with-png**,--with-freetype之類的錯誤 在配置項後面加上-dir參數便可:既修編譯參數爲: ./configure --with-php-config=[php安裝目錄]/bin/php-config --with-jpeg-dir=[jpeg安裝目錄] --with-png-dir=[libpng安裝目錄] --with-freetype-dir=[freetype安裝目錄] --with-zlib=[zlib安裝目錄] --with-gd=[gd安裝目錄] 便可
)
make  
make install  
 
安裝成功後會在「[php安裝目錄]/lib/php/extensions/no-debug-non-zts-20060613」目錄下生成gd.so文件, 
   而後cp [php安裝目錄]/lib/php/extensions/no-debug-non-zts-20060613/gd.so /opt/php/ext 
 
修改php.ini文件加載gd組件,添加extension_dir=/opt/php/ext和extension=gd.so,若是有extension_dir=/opt/php/ext則不須要增長 
Java代碼  
extension_dir=/opt/php/ext  
extension=gd.so 


./configure --with-php-config=/usr/local/php/bin/php-config --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype --with-zlib-dir=/usr/local/zlib --with-gd=/usr/local/gd2

執行編譯安裝
make 
make install
具體操做流程以下:
$ cd <php源碼>/ext/gd
$ /usr/local/php5/bin/phpize
$ ./configure --with-gd=/usr/local/gd --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype --with-zlib-dir=/usr/local/zlib --with-php-config=/usr/local/php/bin/php-config
$ make && make install
 修改php.ini
$ make && make install
添加extension=gd.so
 最後,重啓apache


可能出現的錯誤以及解決方法:

編譯GD庫時若是出現如下錯誤:


 
在./configure GD庫,安裝時出現了一個問題,下面是報錯信息gd_png.c:16:53: error: png.h: No such file or directory
gd_png.c:47: error: expected specifier-qualifier-list before ‘jmp_buf’
gd_png.c:54: error: expected ‘)’ before ‘png_ptr’
gd_png.c:82: error: expected ‘)’ before ‘png_ptr’
gd_png.c:92: error: expected ‘)’ before ‘png_ptr’
gd_png.c:98: error: expected ‘)’ before ‘png_ptr’
gd_png.c: In function ‘gdImageCreateFromPngCtx’:
gd_png.c:125: error: ‘png_byte’ undeclared (first use in this function)
gd_png.c:125: error: (Each undeclared identifier is reported only once
gd_png.c:125: error: for each function it appears in.)
gd_png.c:125: error: expected ‘;’ before ‘sig’
gd_png.c:126: error: ‘png_structp’ undeclared (first use in this function)
gd_png.c:126: error: expected ‘;’ before ‘png_ptr’
gd_png.c:127: error: ‘png_infop’ undeclared (first use in this function)
gd_png.c:127: error: expected ‘;’ before ‘info_ptr’
gd_png.c:128: error: ‘png_uint_32′ undeclared (first use in this function)
gd_png.c:128: error: expected ‘;’ before ‘width’
gd_png.c:131: error: ‘png_colorp’ undeclared (first use in this function)
gd_png.c:131: error: expected ‘;’ before ‘palette’
gd_png.c:132: error: ‘png_color_16p’ undeclared (first use in this function)
gd_png.c:132: error: expected ‘;’ before ‘trans_gray_rgb’
gd_png.c:133: error: expected ‘;’ before ‘trans_color_rgb’
gd_png.c:134: error: ‘png_bytep’ undeclared (first use in this function)
gd_png.c:134: error: expected ‘;’ before ‘trans’
gd_png.c:135: error: expected ‘;’ before ‘image_data’
gd_png.c:136: error: ‘png_bytepp’ undeclared (first use in this function)
gd_png.c:136: error: expected ‘;’ before ‘row_pointers’
gd_png.c:144: error: ‘sig’ undeclared (first use in this function)
gd_png.c:157: error: ‘png_ptr’ undeclared (first use in this function)
gd_png.c:157: error: ‘PNG_LIBPNG_VER_STRING’ undeclared (first use in this function)
gd_png.c:157: error: ‘gdPngErrorHandler’ undeclared (first use in this function)
gd_png.c:166: error: ‘info_ptr’ undeclared (first use in this function)
gd_png.c:182: error: ‘jmpbuf_wrapper’ has no member named ‘jmpbuf’
gd_png.c:192: error: ‘gdPngReadData’ undeclared (first use in this function)
gd_png.c:195: error: ‘width’ undeclared (first use in this function)
gd_png.c:195: error: ‘height’ undeclared (first use in this function)
gd_png.c:196: error: ‘PNG_COLOR_TYPE_RGB’ undeclared (first use in this function)
gd_png.c:196: error: ‘PNG_COLOR_TYPE_RGB_ALPHA’ undeclared (first use in this function)
gd_png.c:204: error: ‘image_data’ undeclared (first use in this function)
gd_png.c:205: error: ‘row_pointers’ undeclared (first use in this function)
gd_png.c:220: error: ‘jmpbuf_wrapper’ has no member named ‘jmpbuf’
gd_png.c:233: error: ‘PNG_COLOR_TYPE_PALETTE’ undeclared (first use in this function)
gd_png.c:234: error: ‘palette’ undeclared (first use in this function)
gd_png.c:238: error: ‘PNG_INFO_tRNS’ undeclared (first use in this function)
gd_png.c:246: error: ‘trans’ undeclared (first use in this function)
gd_png.c:258: error: ‘PNG_COLOR_TYPE_GRAY’ undeclared (first use in this function)
gd_png.c:259: error: ‘PNG_COLOR_TYPE_GRAY_ALPHA’ undeclared (first use in this function)
gd_png.c:261: error: expected ‘)’ before ‘gdMalloc’
gd_png.c:280: error: ‘trans_gray_rgb’ undeclared (first use in this function)
gd_png.c:305: error: ‘trans_color_rgb’ undeclared (first use in this function)
gd_png.c:322: error: ‘rowbytes’ undeclared (first use in this function)
gd_png.c:327: error: expected ‘;’ before ‘gdMalloc’
gd_png.c:345: error: expected ‘;’ before ‘gdMalloc’
gd_png.c:357: error: ‘h’ undeclared (first use in this function)
gd_png.c:381: error: ‘PNG_INTERLACE_ADAM7′ undeclared (first use in this function)
gd_png.c:389: error: ‘w’ undeclared (first use in this function)
gd_png.c:390: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘r’
gd_png.c:390: error: ‘r’ undeclared (first use in this function)
gd_png.c:391: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g’
gd_png.c:391: error: ‘g’ undeclared (first use in this function)
gd_png.c:392: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘b’
gd_png.c:392: error: ‘b’ undeclared (first use in this function)
gd_png.c:401: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘r’
gd_png.c:402: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g’
gd_png.c:403: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘b’
gd_png.c:410: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘a’
gd_png.c:410: error: ‘a’ undeclared (first use in this function)
gd_png.c:419: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘idx’
gd_png.c:419: error: ‘idx’ undeclared (first use in this function)
gd_png.c: In function ‘gdImagePngCtxEx’:
gd_png.c:499: error: ‘png_byte’ undeclared (first use in this function)
gd_png.c:499: error: expected ‘;’ before ‘trans_values’
gd_png.c:500: error: ‘png_color_16′ undeclared (first use in this function)
gd_png.c:500: error: expected ‘;’ before ‘trans_rgb_value’
gd_png.c:501: error: ‘png_color’ undeclared (first use in this function)
gd_png.c:501: error: expected ‘;’ before ‘palette’
gd_png.c:502: error: ‘png_structp’ undeclared (first use in this function)
gd_png.c:502: error: expected ‘;’ before ‘png_ptr’
gd_png.c:503: error: ‘png_infop’ undeclared (first use in this function)
gd_png.c:503: error: expected ‘;’ before ‘info_ptr’
gd_png.c:508: error: ‘png_ptr’ undeclared (first use in this function)
gd_png.c:508: error: ‘PNG_LIBPNG_VER_STRING’ undeclared (first use in this function)
gd_png.c:509: error: ‘gdPngErrorHandler’ undeclared (first use in this function)
gd_png.c:520: error: ‘info_ptr’ undeclared (first use in this function)
gd_png.c:524: error: ‘png_infopp’ undeclared (first use in this function)
gd_png.c:529: error: ‘jmpbuf_wrapper’ has no member named ‘jmpbuf’
gd_png.c:537: error: ‘gdPngWriteData’ undeclared (first use in this function)
gd_png.c:538: error: ‘gdPngFlushData’ undeclared (first use in this function)
gd_png.c:595: error: ‘PNG_INTERLACE_ADAM7′ undeclared (first use in this function)
gd_png.c:595: error: ‘PNG_INTERLACE_NONE’ undeclared (first use in this function)
gd_png.c:602: error: ‘PNG_COLOR_TYPE_RGB_ALPHA’ undeclared (first use in this function)
gd_png.c:603: error: ‘PNG_COMPRESSION_TYPE_DEFAULT’ undeclared (first use in this function)
gd_png.c:604: error: ‘PNG_FILTER_TYPE_DEFAULT’ undeclared (first use in this function)
gd_png.c:609: error: ‘PNG_COLOR_TYPE_RGB’ undeclared (first use in this function)
gd_png.c:617: error: ‘PNG_COLOR_TYPE_PALETTE’ undeclared (first use in this function)
gd_png.c:623: error: ‘trans_rgb_value’ undeclared (first use in this function)
gd_png.c:672: error: ‘trans_values’ undeclared (first use in this function)
gd_png.c:694: error: ‘palette’ undeclared (first use in this function)
gd_png.c:725: error: ‘png_bytep’ undeclared (first use in this function)
gd_png.c:725: error: ‘row_pointers’ undeclared (first use in this function)
gd_png.c:731: error: ‘prow_pointers’ undeclared (first use in this function)
gd_png.c:747: error: expected ‘)’ before ‘gdMalloc’
gd_png.c:804: error: expected ‘)’ before ‘gdMalloc’
make[2]: *** [gd_png.lo] 錯誤 1
make[2]:正在離開目錄 `/usr/local/src/modules/gd-2.0.35′
make[1]: *** [all-recursive] 錯誤 1<br>
make[1]:正在離開目錄 `/usr/local/src/modules/gd-2.0.35′
make: *** [all] 錯誤 2很顯然,這是引入png庫出現的問題,解決方法進入gd源代碼目錄:vi gd_png.c將16行的png.h修改爲 libpng安裝目錄/include/png.h我這邊就是:/usr/local/libpng/include/png.hmake && make install 成功


在安裝php GD擴展時,報以下錯誤服務器

In file included from /kk/php-5.4.0/ext/gd/gd.c:103:app

/root/php-5.4.0/ext/gd/gd_ctx.c: In function ‘_php_image_stream_putc’:ide

/root/php-5.4.0/ext/gd/gd_ctx.c:51: 錯誤:‘struct gdIOCtx’ 沒有名爲 ‘data’ 的成員ui

/root/php-5.4.0/ext/gd/gd_ctx.c: In function ‘_php_image_stream_putbuf’:this

/root/php-5.4.0/ext/gd/gd_ctx.c:58: 錯誤:‘struct gdIOCtx’ 沒有名爲 ‘data’ 的成員spa

/root/php-5.4.0/ext/gd/gd_ctx.c: In function ‘_php_image_stream_ctxfree’:.net

/root/php-5.4.0/ext/gd/gd_ctx.c:67: 錯誤:‘struct gdIOCtx’ 沒有名爲 ‘data’ 的成員

/root/php-5.4.0/ext/gd/gd_ctx.c:68: 錯誤:‘struct gdIOCtx’ 沒有名爲 ‘data’ 的成員

/root/php-5.4.0/ext/gd/gd_ctx.c:69: 錯誤:‘struct gdIOCtx’ 沒有名爲 ‘data’ 的成員

/root/php-5.4.0/ext/gd/gd_ctx.c: In function ‘_php_image_output_ctx’:

/root/php-5.4.0/ext/gd/gd_ctx.c:153: 錯誤:‘gdIOCtx’ 沒有名爲 ‘data’ 的成員

make: *** [ext/gd/gd.lo] 錯誤 1

解決方法

vi <gd_dir>/include/gd_io.h

gdIOCtx結構中增長void *data;

格式以下

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);

  /* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */

  int (*seek) (struct gdIOCtx *, const int);

  long (*tell) (struct gdIOCtx *);

  void (*gd_free) (struct gdIOCtx *);

  void (*data);

}

gdIOCtx;


注:不知道是否是動態擴展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, 問題解決,能夠生成驗證碼.
相關文章
相關標籤/搜索