【问题标题】:Compiling PHP with GD and libjpeg support使用 GD 和 libjpeg 支持编译 PHP
【发布时间】:2011-11-02 07:54:54
【问题描述】:

我编译自己的 PHP,部分是为了了解更多关于 PHP 是如何组合在一起的,部分是因为我总是发现我需要默认不可用的模块,而这样我可以控制它。

我的问题是我无法在 PHP 中获得 JPEG 支持。使用 CentOS 5.6。以下是我编译PHP 5.3.8时的配置选项:

 './configure'  '--enable-fpm' '--enable-mbstring' '--with-mysql' '--with-mysqli' '--with-gd' '--with-curl' '--with-mcrypt' '--with-zlib' '--with-pear' '--with-gmp' '--with-xsl' '--enable-zip' '--disable-fileinfo' '--with-jpeg-dir=/usr/lib/'

./configure 输出显示:

checking for GD support... yes
checking for the location of libjpeg... no
checking for the location of libpng... no
checking for the location of libXpm... no

然后我们可以看到 GD 已安装,但不存在 JPEG 支持:

# php -r 'print_r(gd_info());'
Array
(
    [GD Version] => bundled (2.0.34 compatible)
    [FreeType Support] =>
    [T1Lib Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] =>
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] =>
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] =>
)

我知道 PHP 需要能够找到 libjpeg,但它显然无法找到它满意的版本。我原以为/usr/lib/libjpeg.so/usr/lib/libjpeg.so.62 会是它所需要的,但我为它提供了正确的lib 目录(--with-jpeg-dir=/usr/lib/)并且它没有选择它们所以我猜它们不可能是正确的版本.

rpm 表示已安装 libjpeg。我应该yum remove 并重新安装它,以及它的所有依赖包吗?这能解决问题吗?

这是一个粘贴箱,里面收集了一些有用的系统信息:
http://pastebin.com/ied0kPR6

为服务器故障 (https://serverfault.com/q/304310/92291) 的交叉发布致歉,尽管我试图了解 Stack Exchange 在交叉发布方面的立场,但不清楚:https://meta.stackexchange.com/q/75326/167958

【问题讨论】:

  • 有时配置脚本很笨,你必须使用--with-somelib=/usr 而不是...=/usr/lib,因为配置测试在内部编写为@​​987654336@ 而不仅仅是providedpath。您可能必须在配置测试套件中四处寻找才能找出真正需要的内容。
  • 我试过--with-jpeg-dir=/usr。它确实输出了checking for the location of libjpeg... /usr,但它仍然不支持JPEG。我不知道在哪里查看配置脚本的课程代码 - 你知道我在哪里可以找到它吗?
  • 应该是 configure.in 文件或类似的文件,其中列出了配置脚本应该执行的测试。
  • 是的!我认为这是解决方案。我设置了--with-jpeg-dir=/usr/local/,现在它可以工作了!请将此解决方案作为答案发布,我会接受。
  • @marc-b 您的解决方案帮助我解决了我的问题,因为 PHP 似乎想要我从 /usr/local/lib/libjpeg.so.8 的源代码编译的 libjpeg。我曾尝试告诉它将那个与--with-jpeg-dir=/usr/local/lib/ 一起使用但没有成功,但根据您的评论,我尝试了--with-jpeg-dir=/usr/local/,它奏效了。 :) 谢谢。

标签: php gd compilation centos libjpeg


【解决方案1】:

您很可能需要安装 libjpeg 的开发版本,而不是运行时版本(当然,编译后将需要运行时版本)。

我自己不使用 CentOS,但这样的东西应该会有所帮助:

rpm install libjpeg-devel

我的包名可能有误,但请查找带有 -dev-devel 后缀的内容。

【讨论】:

  • 如果我这样做rpm -qa | grep -e libjpeg,它会说libjpeg-devel-6b-37。大概就够了吧?我确实把它放在我发布的 pastebin 链接中。
  • 抱歉 - 没有查看您的粘贴。如果您的意思是它已经安装,我会说这已经足够了(我不使用rpm)。
  • 如果我不应该使用rpm,我应该从哪里安装它?我尝试从源代码编译它,但似乎很难找到它的“官方”源代码。你知道哪里是下载libjpeg 的最佳位置吗?
  • 我很抱歉;我的意思是“不使用rpm”。我假设-qa 开关列出了已安装的包。
  • 是的。这意味着已安装的软件包。
【解决方案2】:

根据要求:

有时配置脚本很笨,你必须使用--with-somelib=/usr 而不是...=/usr/lib,因为配置测试写成providedpath + '/lib/' 而不是只是在内部提供了路径。您可能需要在配置测试套件中四处寻找才能找出真正需要的内容

【讨论】:

  • 对于 CentOS 7 上的 PHP 7,神奇的咒语是:--with-gd --with-jpeg-dir=/usr/lib64
【解决方案3】:

别忘了做一个

make clean

在你配置之后。

我之前做了一些其他配置和制作,旧安装阻止我在 GD 上启用 jpeg 支持。

它为我节省了 ubuntu 12.04 64bits

我也用过这些包:

aptitude install libjpeg62-dev libpng-dev libfreetype6-dev

使用此配置选项:

./configure \
  --with-config-file-path=/usr/local/apache2/conf \
  --with-jpeg-dir \
  --with-png-dir \
  --with-vpx-dir \
  --with-freetype-dir \
  --enable-apc \
  --enable-bcmath \
  --enable-calendar \
  --enable-dba \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-shmop \
  --enable-sigchild \
  --enable-soap \
  --enable-sockets \
  --enable-sysvmsg \
  --enable-zip \
  --enable-gd-native-ttf  \
  --with-gd \
  --with-apxs2=/usr/local/httpd/bin/apxs \
  --with-bz2 \
  --with-curl \
  --with-gettext \
  --with-mcrypt \
  --with-mysql-sock=/var/run/mysqld/mysqld.sock \
  --with-openssl \
  --with-pdo-mysql \
  --with-xmlrpc \
  --with-zlib

然后:

make clean
make
make install

在 Apache 2.4.3 和 PHP 5.4.11 上运行良好

【讨论】:

  • 对于某些 PHP 版本,您必须在运行配置脚本之前make clean,否则某些文件会丢失。
猜你喜欢
  • 1970-01-01
  • 2014-12-14
  • 2011-06-06
  • 2012-06-23
  • 2012-09-21
  • 1970-01-01
  • 1970-01-01
  • 2018-08-31
  • 1970-01-01
相关资源
最近更新 更多