I've written a HOWTO and a FAQ about running CGI programs. They can be found here:
If that doesn't help you, please let me know.
Make sure you use the php binary in the sapi/cgi directory, NOT the one in sapi/cli.
links to HOWTO and FAQ point to this website instead of old Hiawatha website