CentOS下不重新编译PHP文件的情况下php GD库扩展库的编译安装
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/
freetype-2.1.9.tar.gzhttp://sourceforge.net/projects/freetype/
1、安装 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
2、安装 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
3、安装 libpng
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
4、安装 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
5、安装 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
(如果出错见下文)
6、集成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