First of all, in spite of the fact that the world runs on LAMPS (Linux, Apache, MySQL, PHP, SQL), I really dislike PHP or Python. They are sort of pseudo-Object Oriented and do not have the power of J2EE where one can integrate pure Java classes with JSPs. My preferred approach is LAMJS where J is JSP or Java. Our webserver is Apache Tomcat.
At any rate, we have a rang-dang-doo enterprise app written with Java, JSP, ServerFaces, and all of the good stuff. Our business requirements say that we have to have a blog and a newsletter and a marketing side to our enterprise app. We only have so many developers and we believe in the AGILE approach with continuous iteration and working software. So to put the marketing side in place, we decided not to re-invent the wheel. Wordpress has templates galore and all of the features that we need. Wordpress is written in PHP and uses PHP, so we have to make Tomcat play with JSPs and PHP. It was a hair-pulling experience.
The first thought was to use JavaBridge and JavaBridge.jar. We kept getting this stack trace:
Fatal Error: Failed to start PHP ["php-cgi", "-v"], reason: java.io.IOException: Cannot run program ""php-cgi"" (in directory "C:\Users\Delon"): CreateProcess error=2, The system cannot find the file specified
Could not start FCGI server: java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [php-cgi, -v]
FCGIConnectException: Could not connect to server
ContextLoaderListener. createConnectionPool( ContextLoaderListener.java: 541)
ContextLoaderListener. contextInitialized( ContextLoaderListener.java: 185)
FutureTask$Sync.innerRun( Unknown Source)
ThreadPoolExecutor.runWorker( Unknown Source)
ThreadPoolExecutor$Worker.run( Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: File \\.\pipe\C:\Program Files\Apache Software Foundation\Tomcat 7.0\temp\
JavaBridge3030620009245189355. socket not writable
... 15 more
Caused by: java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [php-cgi, -v]
FCGIConnectionFactory$1.run( FCGIConnectionFactory.java: 109)
Obviously we hadn't configured Tomcat to find the PHP executables which were supposed to be in the .war file. We tried various things like trying to install PHP on Windows (our dev machines are Windows, but our production and test servers are Linux), all to no avail. We found plenty of instructions on how to show Apache how to find the PHP executables, but none for Tomcat.
I was really looking for a plug and play solution, and I found it with Caucho and their Quercus war file. I simply downloaded the war file, and took a copy of it. I changed the copy's .war extension to a .zip extension and unzipped it. I took the resultant folder and dropped it into our webapps folder where Tomcat could find it and it worked first time. Someone ought to preserve their blood for posterity. You too can make PHP play with Tomcat by downloading the war file from here: http://quercus.caucho.com/
Thank you Caucho and Quercus where ever you are.