firstly, make sure that package hasn't already been installed bia RPM (I'm assuming you're running RedHat of some flavor)
If it has, then the newer versions of PHP will see it and automatically use it during install.
to check for the gdlib, do this (as root):
rpm -qa|grep gd
and look for a package named gd-1.x.y-z
where x,y, and z are numbers. If so, then gdlib is already installed. the latest version is around 1.8.3 or so, and does NOT handle gif files.
If it isn't installed, look on your distro's CDROM and see if that RPM file is there, and install it from the CD.
then, when you run the ./configure script in the php source directory, it should pick up on the gd library being there and autoconfigure for it.