There are some compatibility issues between different versions of postgres and php.
If you're installing from source files (i.e. files that end in .tar.gz) then you will want to have the latest of both php and postgresql.
Build apache and postgresql first (order doesn't matter, they won't interact until you build php) and install them to the default directory of /usr/local/apache and /usr/local/pgsql respectively.
THEN, edit /etc/ld.so.conf and add a line like this:
/usr/local/pgsql/lib
and run ldconfig.
In the php source directory, use these two switches for the ./configure command:
--with-pgsql --with-apxs=/usr/local/apache/bin/apxs
and php should now build and all.
After doing a make install on php, you need to edit /usr/local/apache/conf/htttpd.conf and uncomment out the add-handler lines for php4 that are in there. The loadmodule and addmodule directives should already be uncommented.
If apache is already running, restart it (as root) with: apachectl stop, then apachectl start and you should be done.