I've solved the problem. I've compiled PHP and the servlet using buildphp.sh and now it works fine. However, this took me the all day because of not knowing in advance the tools, libraries and devel packages the script uses. There were also some bugs in the script. I'm not sure I've remembered them all:
1. Bad urls to sources to download, but this was easy to find out
2. I've needed to compile JPEG library manually because of some error (I think it was because of using ./libtool instead of libtool) and of course to correct the script
3. I've needed to enable MySQL module, although I didn't want it
4. MySQL compile parameters are missing --enable-thread-safe-client
Maybe it is a good idea to support more source distribution than binaries. Now I think there should be also some easy way to compile just libphp5.so and libphp5servlet.so. Many Linux distros have PHP and modules available as packages, which also are easy to update.
1 - The URL's are in the start of buildphp.sh to make changes easy.
2 - I have fixed something related to this one.
3 - I will test this one.
4 - I have fixed it thanks.
I will prepare a wiki how to build the php package but may be FastCGI is what you are looking for.