Getting the right GD library on any distribution is not that easy. Let's try to explain the basics of how to do it for Drupal 7.

Ubuntu and Windows: http://drupal.org/node/256876 (see subpages)
CentOS: http://drupal.org/node/327731

Since this is such a common problem it would be nice to get a standard solution for people.

Note that Ubuntu 10.04 works "out of the box" and it's PHP 5.3.

Comments

rfay’s picture

One approach to Debian (not tested in this context)

New /etc/apt/sources.list:

deb http://ftp.debian.org/debian lenny main contrib non-free
deb http://www.backports.org/debian lenny-backports main contrib non-freedeb http://security.debian.org/ lenny/updates main contrib non-free

apt-get update
apt-get install php5-gd
(or perhaps apt-get install apache2 mysql-server php5 libapache2-mod-php5 php5-xsl php5-gd php-pear libapache2-mod-auth-mysql php5-mysql mysql-query-browser php5-curl php5-memcache)

This is the approach we use the the testbots on Debian 5/php 5.3.

mgifford’s picture

Subscribe. Will have to find time to test this.

steve.m’s picture

Note that php5-gd is available in the 'main' repos, so it's not necessary to include contrib and non-free.

Also, the version of GD that is installed with php5-gd on Debian still causes Drupal to throw errors because it's not the same GD library as included with mainstream PHP and is missing some features. (The Debian package maintainers take issue with how the PHP team is treating the GD library: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=321237)

Looks like the only way to get rid of those errors is to actually recompile PHP:
http://cumu.li/2008/5/13/recompiling-php5-with-bundled-support-for-gd-on...

rfay’s picture

Title: Improve distro install documentation for Drupal 7 - GD » GD package problems with Debian/Ubuntu: Document distro workarounds

@steve.m, this issue is about the problem you describe, and documenting how to resolve it. The links in the above explain workarounds.

Changing title to make it clearer.

mgifford’s picture

Drupal should never be asking an administrator to recompile PHP. Yikes.

steve.m’s picture

Aha, cool. I just wanted to point out that the apt-get install of php5-gd does not in fact solve the problem.

thomasde’s picture

Any solution without recompile PHP?

rfay’s picture

Yes, the pages in #0 and #1 suggest how to do this on Ubuntu at least.

thomasde’s picture

ohh, sorry, I mean Debian. Does Squeeze work without?

rfay’s picture

#1 is a suggestion for Debian. If you haven't already, could you try it and report back?

arianek’s picture

Issue tags: +server stuff

adding tags

damien_vancouver’s picture

Assigned: Unassigned » damien_vancouver

I perform the build from source step, the debian way, for each new PHP5 version. I'll take on writing a new page to document it properly for Debian, and expanding the existing the instructions for Ubuntu.

The following is a raw dump of my wiki documentation, in case people are curious how to do it before I get this converted to a proper docs page. These docs are for Debian 5.0 Lenny and I copied the steps from a blog post at: http://blog.pirsig.net/apiBlog/entry/compile_php5_gd. I tried to clarify the steps a bit more in my version (which I'll udpate shortly for the Drupal docs):

Debian Lenny: rebuild php with bundled gd

You have to redo this every PHP version upgrade (after each security update)

first make sure the dependancies are there:

sudo apt-get install apache2-prefork-dev build-essential debhelper fakeroot

Now change to the /usr/src dir, remove any old php5 stuff there:

become root ("sudo su", type your password if required), then:

cd /usr/src
rm -rf php5* 

Get the PHP5 source and dependencies:

apt-get source php5
apt-get build-dep php5

Now cd to the php5 dir, it will be named slightly differently to match the version you downloaded, and edit debian/rules:

cd /usr/src/php5-5.2.6.dfsg.1   (dir might be diff if the version is not the same)
vi debian/rules

search for: --with-gd=shared,/usr and replace with just: --with-gd=shared. The edited line in debian/rules will then read:

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

Save debian/rules, and build the packages with:

dpkg-buildpackage -rfakeroot

(this takes a long time, at least half an hour on a fast machine)

Once done, you will find newly compiled PHP5 packages in /usr/src. One of these will be a php5-gd package that is built using the bundled library.

Install it and hold it so aptitude will not immediately "security update" it with the stock version. Again, change the exact version number here to match the version you just built, the 5.2.6.dfsg.1-1+lenny8_amd64 pat will be different!

cd /usr/src
dpkg -i php5-gd_5.2.6.dfsg.1-1+lenny8_amd64.deb 

It should output something like this:

(Reading database ... 57949 files and directories currently installed.)
Preparing to replace php5-gd 5.2.6.dfsg.1-1+lenny6 (using php5-gd_5.2.6.dfsg.1-1+lenny8_amd64.deb) ...
Unpacking replacement php5-gd ...
Setting up php5-gd (5.2.6.dfsg.1-1+lenny8) ...

Now mark it not to upgrade, both to dpkg and aptitude:

echo "php5-gd hold" | dpkg --set-selections
aptitude hold php5-gd
echo "php5-common hold" | dpkg --set-selections
aptitude hold php5-common

(this should prevent it from being overwritten the first time you run security updates, which you should check. Make sure it's not going to reinstall php5-gd as a security update, as the old one will show up as newer. It must be marked as "hold").

NOTE - you have to be careful accepting security updates, or you will clobber this version with a new one.


NOTE2 - if there is a security update for the rest of the php5 packages, you are probably going to have to repeat this entire process to generate a new, up to date php5-gd. We hold the php5 package as well as php5-gd so you don't get version mismatches between your main php5 and our custom php5-gd. The versions have to match exactly. So in short Don't update PHP5 ever without doing this whole procedure (on a test machine first, so you have the package built when you upgrade PHP5 on the other machines). Ctweb04 needs an i386 package so you have to just build on there.

Finally, restart apache:

/etc/init.d/apache2 restart

look at a phpinfo page, under "gd" it should now say:

          gd
GD Support 	enabled
GD Version 	bundled (2.0.34 compatible)
FreeType Support 	enabled
...

Enjoy your bundled php5-gd!

arianek’s picture

Status: Active » Needs review
damien_vancouver’s picture

Now that Debian Squeeze has been released, I must re-visit this again... Perhaps the procedure is different, or no longer necessary!

rfay’s picture

I just took Debian Squeeze for a test run. If you're willing to run PHP 5.3, it seems to have no trouble on D6 out of the box.

D7 also seems to be fine and very happy with GD on all counts.

I recommend that we document for Squeeze and PHP 5.3. The majority (I think) of D6 contrib has adapted to 5.3 by this point, and core has been ready for some time.

If we have to document PHP 5.2 for Squeeze, an approach similar to http://www.randyfay.com/node/63 may work, but then we'll have the GD problems again unless we use dotdeb or something like it. As I remember, the dotdeb repos always solved this problem, but they moved on to PHP5.3 very fast.

skomorokh’s picture

Beyond recompiling the package is there any known and reliable PPA for an appropriate php5-gd on Lenny?
Forcing early migration to Squeeze is not an option nor is making PHP packages a manual affair.

Backports would be a good choice, except apparently there isn't one?
http://packages.debian.org/search?keywords=php5-gd&searchon=names&suite=...

Also, is there any way to disable status messages you don't care about? It is fully unimportant to this particular install (and many others, I imagine) if images can be desaturated or rotated. Some functions of GD are working fine and that suffices. But beyond editing core (and needing to reapply the edit every upgrade) I do not see how to prevent the status message. This makes the status system useless as I do not know if the continuously reported "one or more problems" are the one that I know is there or something new and important!

skomorokh’s picture

(urk, dupe)

thsutton’s picture

I've encountered a number of issues with the stock Debian 6.0 ("squeeze") php5-gd package running D6 with imagecache and imagecache_actions. While ImageAPI doesn't complain any more, ImageCache presets including canvas and file type operations seem not to work very well or at all.

I'm rebuilding php5-gd as described above now and I'll see if that fixes the issues I've seen.

John Pitcairn’s picture

Sub. Considering taking the plunge and upgrading to squeeze.

damien_vancouver’s picture

Hey all,

On the one D7 site I'm building, the stock squeeze packages don't show an error under the status report. instead it says:

OK - GD library PNG support 2.0
OK - GD library rotate and desaturate effects 2.0

But... I assume Drupal 6 is still going to complain. I've also encountered other random problems in the wild hosting Drupal 6 sites on PHP 5.3... so aside from the gd problem, you may also have that larger problem to worry about with the upgrade.

(With Ubuntu you can use methods like http://www.randyfay.com/node/63 to install old LTS packages that are still supported and still PHP 5.2. AFAIK this isn't an option in Debian, and I'm not sure what all of us who depend on PHP 5.2 are going to do come Debian 5 EOL early next year... hopefully not resort to building PHP 5.2 from source.)

Anyway, I will attempt my #12 on my local squeeze server and post the updated procedure here!

damien_vancouver’s picture

Hi guys, so my Debian Squeeze test went OK. Here are the updated instructions. There's an extra step now (editing the debian/setup-mysql.sh script as well as debian/rules) and also the end is slightly different. I've also added the steps I use each new PHP5 security update to upgrade my servers.

I hope this helps! Remember to test out other PHP 5.3 compatibility, or if possible back up/snapshot your server entirely before doing the squeeze upgrade. My first one ended in a very hurried rollback due to OpenAtrium and PHP 5.3 scrapping. I definitely do not recommend you upgrade a physical server to squeeze without first testing your sites somewhere to make sure they will work, because you will be in a world of pain and unable to easily roll back. And with that last word of caution: Good luck upgrading!!!

Debian Squeeze: rebuild php5 packages with bundled gd library, the "Debian Way"

Important Note: You have to redo this EVERY PHP version upgrade (after each security update). Yes I'm serious.

Important Warning: Please read this ENTIRE procedure before starting it. Please don't try it on your production server until you are sure you have it down and everything is going to work.

Prerequisites

First make sure the dependencies are there. You only need to do this once per machine:

sudo apt-get install  apache2-prefork-dev build-essential debhelper fakeroot

Second, you need a phpinfo() page that shows you what version you have so you can see the change. If you don't have one of these, create a simple text file in your web root containing just:

<?php phpinfo(); ?>

and save it as "phpinfo.php" or something. Then verify you can load the page and see the PHP version page. It will list your "gd" version as just "2.0". It should not say "bundled" under the gd version.

Step 1 - remove old build files

Now remove any old php5 stuff from /usr/src (ie. files from last time you did this procedure):

become root ("sudo su", type your password if required), then:

rm -rf /usr/src/php5*

Step 2 - download PHP5 source and build dependencies

Perform this with:

apt-get source php5
apt-get build-dep php5

Step 3 - edit debian specific build files

Now cd to the php5 dir that has been created under /usr/src. It will be named slightly differently from my example to match the version you downloaded. Once inside that directory, edit debian/rules with pico, vi, emacs, or whatever your favourite editor is:

cd /usr/src/
ls -l php5*
cd php5-3.3   (the dir might be different to match the version you just downloaded)
pico debian/rules

Inside debian/rules, search for: --with-gd=shared,/usr and replace with just: --with-gd=shared The edited line in debian/rules will then read:

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

Now Save debian/rules. You will still be in /usr/src/php-5.3.3

(New for Debian 6) - Edit debian/setup-mysql.sh to avoid an error during the test. Solution from http://subject9.wordpress.com/2011/04/23/tutorial-how-to-enable-php5s-im...

pico debian/setup-mysql.sh

Search for: # Start the daemon and add --user=root right after $mysqld, so it looks like this:

# Start the daemon
$mysqld --user=root > $datadir/run.log 2>&1 &

Save the file and exit. You're now ready to build!

Step 4: Build the packages

Now Build the packages "the Debian Way" with:

dpkg-buildpackage -rfakeroot

It's going to build all 25 or so PHP packages (this takes a LONG time, at least half an hour on a fast machine), and should end with an error about not being able to sign the package (as we are not really the package maintainer so don't have his secret key):

 [... hours of stuff ...]
dpkg-deb: building package `php5' in `../php5_5.3.3-7+squeeze3_all.deb'.
dpkg-deb: building package `php-pear' in `../php-pear_5.3.3-7+squeeze3_all.deb'.
 signfile php5_5.3.3-7+squeeze3.dsc
gpg: skipped "Ondřej Surý <ondrej@debian.org>": secret key not available
gpg: [stdin]: clearsign failed: secret key not available

 dpkg-genchanges  >../php5_5.3.3-7+squeeze3_amd64.changes
dpkg-genchanges: not including original source code in upload
 dpkg-source --after-build php5-5.3.3
dpkg-buildpackage: binary and diff upload (original source NOT included)
dpkg-buildpackage: warning: Failed to sign .dsc and .changes file

Now you should find newly compiled PHP5 .deb packages in /usr/src. One of these will be a php5-gd package that is built using the bundled library.

Step 5: Install the package, then mark it as held for upgrades

You need to install it and THEN hold it so apt/aptitude will not immediately "security update" it with the stock version. Again, change the exact version number here to match the version you just built, the 5.3.3-7+squeeze3_amd64 part will be different!

cd /usr/src
ls -l php5*     
dpkg -i php5-gd_5.3.3-7+squeeze3_amd64.deb 

It should output something like this:

(Reading database ... 208826 files and directories currently installed.)
Preparing to replace php5-gd 5.3.3-7+squeeze3 (using php5-gd_5.3.3-7+squeeze3_amd64.deb) ...
Unpacking replacement php5-gd ...
Setting up php5-gd (5.3.3-7+squeeze3) ...
Processing triggers for libapache2-mod-php5 ...
Reloading web server config: apache2.

Now mark it not to upgrade, both to dpkg and aptitude:

echo "php5-gd hold" | dpkg --set-selections
aptitude hold php5-gd
echo "php5-common hold" | dpkg --set-selections
aptitude hold php5-common

(this should prevent it from being overwritten the first time you run security updates, which you should check. Make sure it's not going to reinstall php5-gd as a security update, as the old one will show up as newer. It must be marked as "hold").

NOTE1 - you have to be careful accepting security updates, or you will clobber this version with a new one.

NOTE2 - if there is a security update for the rest of the php5 packages, you are going to have to repeat this entire process to generate a new, up to date php5-gd. You have to rebuild it every time.

NOTE3 - You can build the .deb file on one machine and then install it on several others. But you have to match up the architecture (amd64 vs. i386) and you also have to make sure you pay attention and don't install a php5-gd that is the wrong version compared to the rest of the php5 packages on the machine.

Restart Apache

Finally, restart apache:

/etc/init.d/apache2 restart

look at your phpinfo page, under "gd" it should now say:

          gd
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
...

Enjoy your bundled php5-gd!

And remember not to security update it unless you are applying OTHER php5 security updates.

updating PHP5 with security upates

Here is the procedure I follow for each new PHP security update:

  • On a test/dev machine, upgrade all the php5 pacakges (including php5-gd). This will get you the stock php5-gd again. Go ahead and repeat this entire procedure on this test machine to get yourself the matching, upgraded php5-gd .deb file. Copy the new php5-gd*.deb file over to the production machine(s) so you can install it right away after doing the php5 updates.
  • Now go to your production machine(s) and do the php5 security upgrade (it'll clobber the php5-gd you built last version)
  • Right afterwards install the updated php5-gd you built on the dev/test machine, using the final dpkg -i step above. This will ensure your production machine does not have to wait for all the compiling, or get stuck with a broken php5-gd should something go wrong!
  • Make sure phpinfo()'s output is happy on the machine, never just assume everything went well without testing, as this is a fairly complicated and dicey procedure
  • Remember you have to match up amd64 (also called x86_64) vs. x86 pacakges. Your build machine must have the same architecture as the production machines. This might affect you if your build machine is an old clunker, and your production machines are newer running 64 bit linux!
hansfn’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)