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
總結
以上是生活随笔為你收集整理的CentOS编译安装php扩展gd的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 微软并行编程类库Parallel Ext
- 下一篇: [bbk3100]第7集 - Chapt
