when compiling/installing php you begin with ./configure. After that you do make and make install. Before doing make, edit the file 'Makefile' in the dir 'php-4.0.6' (in my case version 4.0.6). Find a line that begins with 'LTLIBRARY_LDFLAGS = ', in my case it is
LTLIBRARY_LDFLAGS = -rpath $(phptempdir) $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS)
i changed it to
LTLIBRARY_LDFLAGS = -lz -rpath $(phptempdir) $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS)
Now save the file and run make and make install.
That should do it.