Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

How to recompile PHP with GD support on a live server

Michel Nadeau, 08-06-2008
Goal: Recompile PHP to enable GD support on a live production server. Minimize downtime and avoid breaking any dependent modules.

Process:

In our case, the live server was running Nginx and I had to install libjpeg, libpng and zlib before recompiling PHP.

NOTE: this post assumes that you are using a Linux machine and that you are 'root'.

Step 1 - Download files

cd /root
mkdir _tmp
cd _tmp
wget http://voxel.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.29.tar.gz
wget http://internap.dl.sourceforge.net/sourceforge/libpng/zlib-1.2.3.tar.gz
wget ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
wget http://il.php.net/get/php-4.4.8.tar.bz2/from/us.php.net/mirror

I recommend on getting the latest versions of libjpeg, libpng and zlib. For PHP, you should get the SAME version you already have on your live server.

Step 2 - Install libpng

cd /root/_tmp
tar xvfz libpng-1.2.29.tar.gz
cd libpng-1.2.29
./configure
make check
make install

Step 3 - Install zlib

cd /root/_tmp
tar xvfz zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make test
make install

Step 4 - Install libjpeg

cd /root/_tmp
tar xvfz jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-shared --enable-static
make
make install
cp libjpeg.* /usr/lib/

Step 5 - ldconfig

Before installing PHP, just to make sure all our shared libraries are up to date, run:

ldconfig

Step 6 - Recompile PHP

I STRONGLY recommend, to avoid any problem, that you recompile the SAME version of PHP that you previously had.

You should start with finding the original "./configure" line. To do so, simply run "phpinfo();" in a PHP script. The original "./configure" line is at the beginning.

cd /root/_tmp
tar xvfz php-4.4.8.tar.bz2
cd php-4.4.8
./configure --enable-mbstring --enable-mysql --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --enable-fastcgi --with-curl --with-sockets --with-iconv --with-dom --with-gd --with-zlib --with-jpeg-dir=/usr/lib
make

The underlined part is what I added to enable the GD support. The beginning is my original "./configure" line. You should use YOUR original "./configure" line there and then add "--with-gd --with-zlib --with-jpeg-dir=/usr/lib".

Once PHP is compiled with the GD support and the original options, we are ready to install it. To avoid a too long downtime, I suggest you to prepare a small BASH shell...

killall -m "php" # Kill PHP
sleep 3 # Wait to be sure that PHP's killed
make install # Install PHP
sleep 2 # Wait 2 seconds
/usr/local/etc/rc.d/spawn-fcgi.sh # Restart PHP

Our server was running the Nginx Web server and PHP in FastCGI mode; so you definitely have to adapt this BASH shell to your server.

Step 7 - Test GD

Now everything should be running as it was before, except that now PHP has support for GD. Let's test if GD's working with that simple PHP script:

<?php

ini_set
("display_errors",1);
ImageCreateTrueColor(20,40);

?>

If you get a blank page (no error), then everything's working fine.

Mike Peters, 01-20-2009
If you're using PHP with FPM, be sure to patch PHP first as described in this post:

http://www.softwareprojects.com/reso...ment-1602.html

JJ, 08-26-2009
the make command of PHP is giving me an error...

make: *** No targets specified and no makefile found. Stop.

someRandomGuy, 02-05-2012
With centos 6 you can just type

'yum install php-gd'

then

'service httpd restart'

and it should be good to go.
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions