search
Homephp教程php手册不重新编译php安装GD库

不重新编译php安装GD库

Jun 06, 2016 pm 08:13 PM
fphpPrepareInstallmostcompilesoftware package

一、需要的软件包 最好事先准备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
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor