使用 GD 和 libjpeg 支持编译 PHP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7167860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:10:57  来源:igfitidea点击:

Compiling PHP with GD and libjpeg support

phpgdcompilationcentoslibjpeg

提问by Robin Winslow

I compile my own PHP, partly to learn more about how PHP is put together, and partly because I'm always finding I need modules that aren't available by default, and this way I have control over that.

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

My problem is that I can't get JPEG support in PHP. Using CentOS 5.6. Here are my configuration options when compiling PHP 5.3.8:

我的问题是我无法在 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/'

The ./configureoutput says:

./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

And then we can see that GD is installed, but that JPEG support isn't there:

然后我们可以看到安装了 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] =>
)

I know that PHP needs to be able to find libjpeg, and it obviously can't find a version it's happy with. I would have thought /usr/lib/libjpeg.soor /usr/lib/libjpeg.so.62would be what it needs, but I supplied it with the correct lib directory (--with-jpeg-dir=/usr/lib/) and it doesn't pick them up so I guess they can't be the right versions.

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

rpmsays libjpeg is installed. Should I yum removeand reinstall it, and all it's dependent packages? Might that fix the problem?

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

Here's a paste bin with a collection of hopefully useful system information:
http://pastebin.com/ied0kPR6

这是一个带有希望有用的系统信息集合的粘贴箱:http:
//pastebin.com/ied0kPR6

Apologies for cross-posting with Server Fault ( https://serverfault.com/q/304310/92291) although I tried to discover what Stack Exchange's position on cross-posting was and it wasn't clear: https://meta.stackexchange.com/q/75326/167958

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

采纳答案by Marc B

as requested:

按照要求:

Sometimes the configure script is dumb, and you have to do --with-somelib=/usr instead of ...=/usr/lib, because the config test is written as providedpath + '/lib/' rather than just providedpath internally. You may have to dig around inside the configure test suite to find out what's really required

有时配置脚本很笨,你必须做--with-somelib=/usr 而不是...=/usr/lib,因为配置测试被写成providedpath + '/lib/' 而不仅仅是providepath 内部. 您可能需要深入了解配置测试套件以找出真正需要的内容

回答by Stanislas Nichini

Don't forget to do a

不要忘记做一个

make clean

make clean

after you configure.

配置后。

I've got make some other configuration and make before and the old installation prevent me to got the jpeg support enabled on GD.

我之前已经进行了一些其他配置和 make,旧的安装阻止我在 GD 上启用 jpeg 支持。

It saves me on ubuntu 12.04 64bits

它为我节省了 ubuntu 12.04 64 位

I've also use these packages :

我也使用过这些包:

aptitude install libjpeg62-dev libpng-dev libfreetype6-dev

with this configure options:

使用此配置选项:

./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

and then :

进而 :

make clean
make
make install

Run good with Apache 2.4.3 and PHP 5.4.11

在 Apache 2.4.3 和 PHP 5.4.11 上运行良好

回答by Bojangles

You most probably need to install the development version, not the run-time version, of libjpeg (of course, the run-time version will be needed once you've compiled).

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

I don't use CentOS myself, but something like this should help:

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

rpm install libjpeg-devel

I might have the package name wrong, but look for something with a -devor -develpostfix.

我可能把包名弄错了,但请寻找带有 a-dev-develpostfix 的东西。