不重新编译php安装GD库
一、需要的软件包 最好事先准备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)前提
- 找到[php的解压目录],就是第一次编译php时解压php的目录,这个每个人有不同的习惯,楼主是在
/usr/local/install/php/
, 如果实在找不到,可以下载一个同版本的php,然后解压。 - 找到[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
原文地址:不重新编译php安装GD库, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





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

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

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

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
