22

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.

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:

 './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 ./configure output says:

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:

# 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.so or /usr/lib/libjpeg.so.62 would 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.

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

Here's a paste bin with a collection of hopefully useful system information:
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

Community
  • 1
  • 1
Robin Winslow
  • 10,908
  • 8
  • 62
  • 91
  • 2
    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. – Marc B Aug 23 '11 at 21:38
  • I tried `--with-jpeg-dir=/usr`. It did output `checking for the location of libjpeg... /usr`, but it still doesn't have JPEG support. I couldn't work out where to view the course code for the configure script - do you know where I might find it? – Robin Winslow Aug 23 '11 at 21:49
  • should be configure.in file or something similiar which lists the tests the configure script should perform. – Marc B Aug 23 '11 at 21:52
  • 1
    Yeah! I think this was the solution. I set `--with-jpeg-dir=/usr/local/` and now it works! Please post this solution as an answer and I'll accept it. – Robin Winslow Aug 23 '11 at 23:43
  • @marc-b Your solution helped me solve my problem because it seems PHP wanted the `libjpeg` I compiled from source in `/usr/local/lib/libjpeg.so.8`. I had tried telling it to use that one with `--with-jpeg-dir=/usr/local/lib/` without success, but following your comment, I tried `--with-jpeg-dir=/usr/local/`, which worked. :) thanks. – Robin Winslow Aug 24 '11 at 10:10
  • @MarcB please add your solution as an answer so I can accept it. Please? – Robin Winslow Sep 14 '11 at 17:24
  • Make sure you do "make clean" BEFORE running "make". For me, this was the missing critical step :-) – Peter Z Aug 25 '17 at 15:21

3 Answers3

20

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

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • 4
    For PHP 7 on CentOS 7, the magic incantation is: `--with-gd --with-jpeg-dir=/usr/lib64` –  Dec 18 '15 at 17:14
15

Don't forget to do a

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.

It saves me on ubuntu 12.04 64bits

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

  • As of some PHP version, you’ll have to `make clean` *before* you run the configure script, or some files will be missing. – Ry- Jul 01 '14 at 23:54
1

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

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

rpm install libjpeg-devel

I might have the package name wrong, but look for something with a -dev or -devel postfix.

Bojangles
  • 99,427
  • 50
  • 170
  • 208
  • If I do `rpm -qa | grep -e libjpeg` it says `libjpeg-devel-6b-37`. Presumably that's enough? I did put this in the pastebin link I posted. – Robin Winslow Aug 23 '11 at 21:43
  • Sorry - didn't look at your paste. I'd say that's plenty enough, if you mean it's already installed (I don't use `rpm`). – Bojangles Aug 23 '11 at 21:44
  • If I shouldn't use `rpm`, where should I install it from? I tried compiling it from source, but it seems to be ridiculously hard to find the "official" source for it. Do you know where would be the best place to download `libjpeg` from? – Robin Winslow Aug 23 '11 at 21:47
  • My apologies; I meant "_I_ don't use `rpm`". I'm assuming the `-qa` switch lists installed packages. – Bojangles Aug 23 '11 at 21:50
  • Yep. It means installed packages. – Robin Winslow Aug 23 '11 at 22:53