日期:2014-05-17  浏览次数:20613 次

php 安装gd库
php 安装gd库
1、查看php信息
php -v

[root@TJSJHL242-181 achievo]# php -v
PHP 5.3.6 (cli) (built: Aug 19 2011 19:35:20)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

2、
一、phpize是干嘛的?

phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块



什么时候我们要用phpize呢?

我们在安装php时:

'./configure' '--prefix=/usr/local/php' '--with-mysql=/usr/local/mysql' '--with-zlib-dir' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-gd' '--enable-ftp' '--with-iconv' '--with-gettext' '--with-curl' '--enable-fastcgi' '--with-openssl'

后面根的参数是我们要的模块,但是随着工作的需要,我们还要在加些模块,又不想重新编译php,这些我们就可以用phpize了。



二、如何使用phpize?

当php编译完成后,php的bin目录下会有phpize这个脚本文件 。在编译你要添加的扩展模块之前,执行以下phpize就可以了;

------------------------------------
# 如果在编译的时候忘记添加某些模块,可以使用这种办法来重新编译添加!
# 首先,进入PHP目录(未编译)的扩展目录
cd /home/soft/php-5.2.14/ext/ftp/
# 调用phpize程序生成编译配置文件
# find / -name phpize
/usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
# 编译扩展库
/configure –with-php-config=/usr/local/php/bin/php-config
make
# make成功执行后,生成的扩展库文件在当前目录的 modules 子目录下
# 编辑php.ini文档,找到extension_dir的目录,将编译好的扩展文件复制到extension下面
vim /usr/local/php/etc/php.ini
# 第491行
# extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
cp ftp.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
# 在php.ini的添加扩展库位置,设置要添加的扩展库。
# 在612处添加 extension=ftp.so
# 重启webservice
------------------------------------------------------
181的php源码位置在
/root/software/php-5.3.6

----------------------------------------
这两天尝试在以上平台安装个Xenforo论坛,安装开始时提示以下信息:

The following errors occurred while verifying that your server can run XenForo:

* The required PHP extension MySQLi could not be found. Please ask your host to install this extension.
* The required PHP extension GD could not be found. Please ask your host to install this extension.

由于PHP是源码编译安装的,所以以上两个扩展都没安装,下面是为PHP添加这两个扩展的过程:


一、安装GD扩展

1.下载安装GD库扩展所需源码包(可点击源码包直接下载)

gd-2.0.35.tar.gz           http://www.libgd.org/releases/

jpegsrc.v8b.tar.gz        http://www.ijg.org/

libpng-1.5.0.tar.gz        http://sourceforge.net/projects/libpng/

freetype-2.4.4.tar.gz     http://sourceforge.net/projects/freetype/

zlib-1.2.3.tar.gz

2.分别编译安装各个源码包

安装zlib

tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install

安装libpng

tar zxvf libpng-1.5.0.tar.tar
cd libpng-1.5.0
cd scripts
mv makefile.linux ../makefile
cd ..
make
make install

安装freetype

tar zxvf freetype-2.4.4.tar.gz
cd freetype-2.4.4
./configure
make
make install

安装Jpeg

tar zxvf jpegsrc.v8b.tar.gz
cd jpeg-8b
./configure –enable-shared
make
make test
make install
注意,这里configure一定要带–enable-shared参数,不然,不会生成共享库

安装GD库
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure –with-png –with-freetype –with-jpeg
make install

3.重新编译安装PHP(即是在以前编译PHP的参数后面再加上以上安装的相关参数)

cd php-5.3.4 (进入以前的PHP源码目录)

./configure –prefix=/opt/php –with-mysql=/opt/mysql –with-apxs2=/opt/apache/bin/apxs –enable-track-vars –enable-force-cgi-redirect –with-config-file-path=/opt/php/etc