升级Ubuntu系统中的GD库到完整版


一般情况下我们在Ubuntu的Linux发行版本中安装LAMPP环境都是直接通过apt-get的方式来进行安装(方便,可以偷懒!呵呵)!

虽然很方便,但是在这些集成版本中多多少少也存在一些问题。

比方说PHP5-GD库~ 我们安装好后发现phpinfo中的提示是 2.0 or higher. 虽然大部分的功能都有,但是这个库并不完整。

在一次西林我做 Drupal项目中就出现 Drupal 报错,导致image模块的部分功能缺失!开始还很诧异,问了一下朋友,朋友说应该不会出现这样的问题(后来才知道,他一直都是编译安装 T-T)。

 

报错的信息如下:

GD Image Filtering 和 GD Image Rotation 无法正常工作,系统提示的意思为该GD库版本不是官方的发行版本!

于是我开始在网上找这方面的问题,发现所有的Ubuntu和debian用户都存在这样的问题。

因为使用DRUPAL国内用户少,所以问题不是很明显。去国外的一些网站查的时候找到了解决办法。(E文太差,找起来费劲!)

主要问题就在GD库上,很多人说APT包中的GD库是被修改过的,然后再编译整合。所以会出现不能功能的缺失。既然找到问题所在了就有办法解决。我在 Cumu.li 的网站上看到他提出的解决办法。BLOG原文如下:

I’ve been installing the LAMP stack on an Ubuntu based server for a client. They rely on the version of LibGD that’s bundled with PHP5. This version includes certain functions including imagerotate() and others.

It seems that the people who build Ubuntu (and Debian) distribution do not want to compile PHP5 with the version of GD that comes bundled with PHP5. As far as I can tell the guys at Ubuntu (and Debian) consider this to be a fork of the original GD library and think that this could be a security risk. Their stance on it is that if PHP want to use this version then they should contribute the changes that have been made to the original GD library back to the core project. This seems fair enough, but unfortunately I can’t immediately change the direction of an open source project this big – or probably any project, come to think about it!

After a bit of rummaging around on the Internet I found nothing to do with actually compiling in this support, so I tried to work out how to do this… In theory! I found a link on Ubuntu forums about including the GMP library I roughly followed this through.

(西林我的E文水平差就不献丑翻译了!基本就是建议大家重新下载源码,然后在编译打包!)

具体操作如下:

先下载个源码包
# Install build tools, debian helpers and fakeroot
apt-get install build-essential debhelper fakeroot
# source code should reside in /usr/src
cd /usr/src
# Download PHP source
apt-get source php5
# Install all packages required to build PHP5
apt-get build-dep php5
cd php5-5.2.3在Download PHP source后程序会自动把压缩的包进行解压,所以我们在我们只需要进入解压后的目录中先修改 debian/rules 文件中的

--with-gd=shared,/usr --enable-gd-native-ttf .

修改成:

--with-gd=shared --enable-gd-native-ttf .


然后保存退出,对源码进行编译,命令如下:

# build the php5-* packages 注意编译过程相当漫长,需要慢慢等待
dpkg-buildpackage -rfakeroot
cd ..
# Install the new php5-gd package
dpkg -i php5-gd_5.2.3-1Ubuntu6.3_i386.deb


OK了以后我们就可以直接将包进行安装了。当然别忘了重启apache2的服务。

然后我们通过PHPINFO来检查安装后的环境GD库部分提示明显就变了,信息提示如下:

GD Version bundled (2.0.34 compatible)

这样你的完整的GD库就安装好了。

最后西林提醒一下大家,上诉流程的距离我也是直接COPY cumu.li的原文。在实际的安装打包的时候,大家要看仔细你的包名称,可不能直接COPY我的代码。

像我安装的时候我的源码包名称就是 php5-5.2.3-org.1,所以这个地方大家的操作需要仔细一点!OK,还愣什么,去升级你的GD库吧~!

相关内容

    暂无相关文章