Since PHP is not supported by GAE as of this writing, we need to run it on the Java platform that is supported.
Fortunately, there’s a PHP 5 implementation in Java that let’s us do just that. The thing is called Quercus PHP and is developed by Caucho. http://quercus.caucho.com/
Here’s a good reference document for the first few steps that involve setting up your local box with GAE Java SDK: http://code.google.com/appengine/docs/java/gettingstarted/installing.html
1. Get Java 6, more precisely Java SE Development Kit 6. According to Google you can use Java 5 for Macs (http://java.sun.com/javase/downloads/widget/jdk6.jsp) While the JDK installs itself, move on to the next step.
2. Get Eclipse IDE for Java EE Developers. http://eclipse.org
3. Get Google App Engine plugin for Eclipse. Again, Google has a nice page that describes the process in greater detail: http://code.google.com/appengine/docs/java/tools/eclipse.html – see Installing the Google Plugin for Eclipse section. One note, once you get to the License Agreements screen, just click on Finish. The Next button will remain grayed out no matter what.
I then followed the instructions under Creating a Project on this page: http://code.google.com/appengine/docs/java/tools/eclipse.html
Once I got the Guestbook example to work it was time to get the Quercus PHP to work. Here’s a reference from the Quercus creators: http://blog.caucho.com/?p=187 and another useful page is here: http://blog.herbert.groot.jebbink.nl/2009/05/using-php-on-gae.html
This is what I did:
- Downloaded the latest Resin application server: http://www.caucho.com/download/ I used open source version.
- Unzipped the file.
- Went to the unzipped directory, selected lib/resin.jar and copied it to my projects war/WEB-INF/lib folder.
- Having the Guestbook example still open, right clicked on the project name, chose Build Path->Configure Build Path, selected Libraries tab, and then added resin.jar from the ‘war/WEB-INF/lib’ folder by clicking on the Add JARs… button. Clicked OK.
- Copied the following to my war/WEB-INF/web.xml file. The existing code can remain there, I just pasted this below. Also, the version from the Caucho’s blog needed some adjustments, so here’s the version that worked for me:
- Next, I pasted this to war/WEB-INF/appengine-web.xml – again under the existing code:
This is supposedly needed to make sure the .php files get processed by PHP and not served up as text.
- Then I added index.php to war/WEB-INF and simply put this in the file:
- Selected the project, Guestbook, on the top menu chose Run->Debug As->Web Application
- Finally, went to http://localhost:8888/index.php and marveled at the miracle.