Warning: I am not an expert on anything that I did here to make PHP work, nor am I likely following the best practices for doing something like this. Experiment at your own risk.
I’m going to cut to the chase here. If Ruby on Rails can run on Google’s App Engine (via JRuby) I figured that there is no reason why PHP shouldn’t be able to work. Of course I wasn’t interested in writing my own PHP interpreter in Java or something like, so I used Google to find Quercus.
Using the instructions to get JRuby working, as well this very useful guide about getting Groovy to work, I set off to piece together something for PHP using Quercus. My biggest problem during this whole process was extracting the jar’s I needed. For some reason, anything I downloaded from the quercus website wouldn’t extract correctly on my Mac or my PC… with the specific quercus.jar file being corrupt. After dropping them into my war/WEB_INF/lib folder and starting my Web Application (I’m using Eclipse FYI) I would get errors about zip not being able to do its job.
Google helped me find a SVN repo out there that had the 3 jars I needed, and after loading them into the correct folder. Eclipse stopped throwing errors. If you’re looking for the files I used, you can find them here: http://lportal.svn.sourceforge.net/viewvc/lportal/portal/trunk/lib/development/. I determined that quercus.jar, resin_util.jar, and script-10.jar were needed for Quercus to do its thing correctly… at least that’s what I think. Drop them in the WEB_INF/lib folder and you should be all set.
Configuring PHP to work was surprisingly easy. Edit web.xml to have the following lines:
I don’t know if any order is important here, but I put the php servlet first, followed by the default servlet, followed by the php servlet-mapping, followed by the default servlet-mapping. By default I mean the one that was generated for me when they thought I wanted to use Java.
Next on the to-edit list was appengine-web.xml. I can’t take credit for knowing to do this, I read it on purrrgatory’s twitter. I added the following lines, right after the close of the system-properties tag.
<exclude path="/*.php" />
<include path="/**.php" />
Looking back at that file I wonder if my exclude path is correct…. but hey its working. I’m not going to complain. I created a php.ini, which is completely blank at the moment, in war/WEB_INF. I think I can put stuff here later.
The last step: write some PHP. I through together the lamest test php file I could imagine, and saved it as war/index.php.
Initially when I tested this out I was getting a wierd error about org.mortbay.util.ajax.Continuation not being there. I don’t know what that is, but its included in the jetty-util-6.1.0.jar file, which I found here. I’m unsure if this is specific to the development platform (where I know jetty is used) or required somewhere in the Quercus mix.
Once in a blue moon, when I start the application up I get an error “java.lang.ClassNotFoundException: `org.mortbay.jetty.handler.ContextHandler’ not valid: java.lang.ClassNotFoundException: org.mortbay.jetty.handler.ContextHandler” but refreshing the page seems to clear that up.
I deployed to Google App Engine and everything worked perfectly! (http://txter.appspot.com/)
Of course I quickly remembered the JDBC wasn’t supported, so in turn the database wrappers that I could easily enable from Quercus weren’t going to work. I’ll play around with this more, trying to figure out how to get it to interact with DataStore or something.
Here are some screenshots incase you’re as confused as I was when I started out with all this.
And I’ve uploaded my war directory, incase its of any help.
Best of luck!
— UPDATE 1 —
Initially, I was very wearsome of getting PHP to talk nicely with the datastore. Doesn’t look like it will be too bad to sort out. I’ll post a more detailed post about getting the datastore to work cleanly… maybe with a nice php or java wrapper class, but for now I’ve posted some sample code here . The two .java files went in my source/projname/ directory, and the php file went with the other PHP files.