一、需要的软件包 最好事先准备freetype, gd, jpeg, png, tool, zlib 这些文件包 如果嫌麻烦,可以下载我打包好的文件包phpgd_software.zip 里面包含 freetype-2.1.9.tar.gz gd-2.0.33.tar.gz jpegsrc.v6b.tar.gz libpng-1.2.10.tar.gz libtool-2.4.2 (1).ta
最好事先准备freetype, gd, jpeg, png, tool, zlib 这些文件包
如果嫌麻烦,可以下载我打包好的文件包phpgd_software.zip
里面包含
1 2 3 4 5 6 7 8 |
? 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安装文件所需(如下)目录,防止提示类似“无法创建一般文件‘/usr/local/jpeg/***’: 没有那个文件或目录” 的错误
1 2 3 4 5 6 7 8 9 |
? 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 ? |
开始安装
1 2 3 4 5 6 7 8 |
? wget ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/jpeg.tar.gz tar-zxf jpeg.tar.gz cd jpeg-6b ./configure--prefix=/usr/local/jpeg--enable-shared--enable-static make make install ? |
如果遇到./libtool: Command not found
错误,查看4.1
1 2 3 4 5 6 7 8 |
? 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 ? |
1 2 3 4 5 6 7 8 9 |
? 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 ? |
1 2 3 4 5 6 7 8 9 |
? 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 ? |
如果遇到error: ‘struct gdIOCtx’ has no member named ‘data’
错误,查看4.2
/usr/local/install/php/
, 如果实在找不到,可以下载一个同版本的php,然后解压。/usr/local/php
[php的解压目录]/ext/gd/
[php的安装目录]/bin/phpize
1 2 3 |
? ./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安装目录] ? |
示例:
1 2 3 4 5 6 7 8 9 10 11 12 |
? -------进入[php的解压目录]/ext/gd/ cd/usr/local/install/php/ext/gd/ ? -------执行phpize /usr/local/php/bin/phpize ? -------生成configure配置 ./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 ? |
注:[php的解压目录]=/usr/local/install/php/, [php的安装目录]=/usr/local/php
执行成功之后,会在extension目录下生成一个gd.so的文件
如:[php安装目录]/lib/php/extensions/no-debug-non-zts-20060613目录下生成gd.so文件
修改php.ini,增加以下语句,动态加载gd.so
1 2 3 |
? extension=gd.so?? ? |
如果是apache, 重启apache
如果是nginx+phpfpm, 重新加载phpfpm
1、解决./libtool: Command not found
出现这个问题的原因可能有两个:
解决方法:
/usr/share/libtool/config.sub
或者 /usr/share/libtool/config/config.sub
1 2 3 4 |
? ????cp/usr/share/libtool/config.sub. ????cp/usr/share/libtool/config.guess. ? |
2、解决error: ‘struct gdIOCtx’ has no member named ‘data’
这个错误算是php5.4的bug,下面对应的两篇文章有对应的说明:
https://bugs.php.net/bug.php?id=55224
https://bugs.php.net/bug.php?id=60108
解决方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
? typedefstructgdIOCtx { ??int(*getC)(structgdIOCtx*); ??int(*getBuf)(structgdIOCtx*,void*,int); ? ??void(*putC)(structgdIOCtx*,int); ??int(*putBuf)(structgdIOCtx*,constvoid*,int); ? ? ??int(*seek)(structgdIOCtx*,constint); ? ??long(*tell)(structgdIOCtx*); ? ??void(*gd_free)(structgdIOCtx*); ??void(*data);???????? //------增加这一行 } gdIOCtx; ? |
原文地址:不重新编译php安装GD库, 感谢原作者分享。