Heim  >  Artikel  >  php教程  >  不重新编译php安装GD库

不重新编译php安装GD库

WBOY
WBOYOriginal
2016-06-06 20:13:461155Durchsuche

一、需要的软件包 最好事先准备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
里面包含

  • 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).tar.gz
  • zlib-1.2.7.tar.gz

二、安装

1、安装 zlib

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

?

2、安装 jpeg

安装前先创建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

3、安装 libpng

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

?

4、安装 freetype

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

?

5、安装 GD

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

三、集成PHP GD扩展 到PHP里

(1)前提

  1. 找到[php的解压目录],就是第一次编译php时解压php的目录,这个每个人有不同的习惯,楼主是在 /usr/local/install/php/, 如果实在找不到,可以下载一个同版本的php,然后解压。
  2. 找到[php的安装目录], 如/usr/local/php

(2) 到php的解压目录

  • 进入[php的解压目录]/ext/gd/
  • 执行 [php的安装目录]/bin/phpize
  • 生成configure配置

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文件

(3)php.ini

修改php.ini,增加以下语句,动态加载gd.so

1

2

3

?

extension=gd.so??

?

(4)重启server

如果是apache, 重启apache
如果是nginx+phpfpm, 重新加载phpfpm

四、错误集锦

1、解决./libtool: Command not found
出现这个问题的原因可能有两个:

  • 没有安装libtool
  • 没有找到config.sub等

解决方法:

  • 如果没有安装libtool,请安装
  • 找到 libtool的config.sub 和 config.guess
    可能在/usr/share/libtool/config.sub 或者 /usr/share/libtool/config/config.sub
    然后进入gd的解压目录,并复制到gd的目录下

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

解决方法:

  • 找到gd_io.h, 就在gd的安装目录下,如果你完全按照上面的路,就在/usr/local/gd2/include/
  • 编辑gd_io.h, 在gdIOCtx结构中增加void *data;

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;

?

  • 执行make clean,然后重新make
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn