By adding Java to their App Engine, Google has opened the door for a whole slew of languages that have been implemented on the JVM, now including PHP via Quercus.

This weekend I decided to give it a try and deploy an old tutorial of mine - PHP Tutorials - on GAE.

I must admit that I was pleasantly surprised by how effortless it was. OK, it’s a very rudimentary PHP application, the only PHP code used was to run the examples described on the code blocks and do some includes; nevertheless I didn’t feel the need to change a single line of code.

Also, deploying a Java application to GAE is simpler than a Python one. Not only because you have a very handy Eclipse plugin, but you will also find configuring the file appengine-web.xml a lot easier when compared to app.yaml.

All you need to do in order to deploy a PHP application, at least as simple as the one I’ve tried, is to follow these steps:

  1. Install Google Plugin for Eclipse.

  2. Create a Web Application Project in eclipse. The complete project directory looks like this:

        ...Java source code...
          ...other configuration...
        ...JSPs, images, data files...
            ...JARs for libraries...
            ...compiled classes...
  3. Copy all your PHP and static files to your-project/war.

  4. Download Quercus binary (WAR file).

  5. Unzip it and copy all files inside quercus.war/WEB-INF/lib to your-project/war/WEB-INF/lib.

  6. Edit your deployment descriptor file web.xml. Mine looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <web-app xmlns:xsi=""
        xmlns="" xmlns:web=""
        <description>PHP Tutorial</description>
            <servlet-name>Quercus Servlet</servlet-name>
            <servlet-name>Quercus Servlet</servlet-name>
  7. Edit your configuration file appengine-web.xml. Mine looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <appengine-web-app xmlns="">
        <!-- Configure java.util.logging -->
            <property name="java.util.logging.config.file" value="WEB-INF/" />
            <include path="/**" expiration="600s" />
            <include path="/**.png" expiration="30d" />
            <include path="/**.jpg" expiration="30d" />
            <include path="/**.gif" expiration="30d" />
            <include path="/**.ico" expiration="30d" />
            <include path="/**.swf" expiration="30d" />
            <include path="/**.css" expiration="7d" />
            <include path="/**.js" expiration="2d 12h" />
            <exclude path="/**.php" />
            <exclude path="/**.inc" />
            <include path="/**.php" />
            <include path="/**.inc" />

The application element must match the application identifier of your application on Google App Engine.

Et voilĂ , you are done!

Now, run your application using the Run As >> Web Application command.

And finally, press the “Deploy App Engine Project” button to deploy to GAE.

Update: This article has been ported to the Miscellaneous section of my PHP Tutorial. Check Run PHP on Google App Engine page for updates.


comments powered by Disqus