One trick you can use to help you build packages from source on debian-based systems is to look at the source package page for the official package. For the lucid php5 see this page (http://packages.ubuntu.com/source/lucid/php5). As you scroll down on that page you can see a list of all the build dependencies for the official package. To build the package yourself you are probably going to need to install everything in that list before you will be able to perform compile the source using a similar set of configuration options. If you are recompiling because you want some features disabled you may be able to skip some of the things in the list.
Here is the Build-Depends for the official package. This will probably tell you exactly what all you n eed. This is from the this file http://archive.ubuntu.com/ubuntu/pool/main/p/php5/php5_5.3.2-1ubuntu4.dsc
Build-Depends: apache2-prefork-dev, autoconf (>=2.63), automake (>=1.11) | automake1.11, bison,
chrpath, debhelper (>=5), flex, freetds-dev, hardening-wrapper, libapr1-dev (>=1.2.7-8),
libbz2-dev, libcurl4-openssl-dev, libdb-dev (>=4.7) | libdb4.8-dev | libdb4.6-dev,
libenchant-dev, libexpat1-dev (>=1.95.2-2.1), libfreetype6-dev, libgcrypt11-dev,
libgd2-xpm-dev, libglib2.0-dev, libgmp3-dev, libicu-dev, libjpeg-dev | libjpeg62-dev,
libkrb5-dev, libldap2-dev, libmhash-dev (>=0.8.8), libmysqlclient-dev, libpam0g-dev,
libpcre3-dev (>=6.6), libpng12-dev, libpq-dev, libpspell-dev, librecode-dev, libsasl2-dev,
libsnmp-dev, libsqlite0-dev, libsqlite3-dev, libssl-dev, libt1-dev, libtidy-dev,
libtool (>=2.2), libwrap0-dev, libxmltok1-dev, libxml2-dev, libxslt1-dev (>=1.0.18), netbase,
quilt, re2c, unixodbc-dev, zlib1g-dev, libedit-dev, tzdata
If you are just enabling a particular option it may be far easier to just grab the package source for your distro-release and tweak the rules/control file and rebuild the package. If you need a newer version you might check to see if a newer release is in the unstable branch and try back-porting it.