Installing GD 1.3 for PHP on Linux

by Nathan Wallace (Oct 25, 1999)

Introduction

This document describes the installation of the GD graphics library on Linux for use with PHP. We are using an old version of this library since newer versions do not allow the generation of gif files due to patent problems.

I've assumed that you have Apache and PHP installed in /usr/local/etc/php as per my instructions.

Getting GD

  1. You need to be working as root to install gd.
        su root
    
  2. I like to keep a copy of my downloaded programs in
        /usr/local/download
    
    So create this directory if you don't already have one.

  3. You can download GD from here.

  4. Save the file as:
        /usr/local/download/gd1.3.tar.gz
    
    using these commands:
        cd /usr/local/download
        ftp ftp.example.com
        cd pub
        cd gd
        bin
        get gd1.3.tar.gz
        bye
    

Installing GD

  1. First we have to unpack the download. We are going to install it into /usr/local/gd1.3. I've used a pretty cryptic tar command below to do it all in one hit.
        cd /usr/local/download
        tar xzf gd1.3.tar.gz -C ..
    

  2. Let's make the GD stuff easy to find:
        cd ..
        ln -s gd1.3 gd
    

  3. Now we need to compile everything:
        cd gd
        make
    

Checking it Worked

  1. You can run the gddemo program to check that the installation is working:
        ./gddemo
    

  2. This demo program generates a gif file:
        demoout.gif
    
    which you can look at in your browser by downloading it from your server or calling up the file directory.

Adding GD Support to PHP

  1. Jump into the php installation directory:
        cd ../etc/php
    

  2. We need to configure PHP to use GD. You should just use the configure command that you used last time and add --with-gd=/usr/local/gd to it. If you followed my instructions for installing PHP with MySQL then your configure command will look like this:
        ./configure --with-apache=../httpd --with-mysql=/usr/local/mysql --enable-track-vars --with-gd=/usr/local/gd
    

  3. Make the new PHP library:
        make
        make install
    

  4. Now we have to remake apache to use the new PHP:
        cd ../httpd
        make
        make install