Table of Contents
一、需要的软件包
二、安装
1、安装 zlib
2、安装 jpeg
3、安装 libpng
4、安装 freetype
5、安装 GD
三、集成PHP GD扩展 到PHP里
(1)前提
(2) 到php的解压目录
(3)php.ini
(4)重启server
四、错误集锦
Home php教程 php手册 不重新编译php安装GD库

不重新编译php安装GD库

Jun 06, 2016 pm 08:13 PM
f php Prepare Install most compile software 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 of this Website
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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles