Running Quercus PHP on App Engine

Here are the steps I took to get PHP running on Google App Engine.

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:

  1. Downloaded the latest Resin application server: http://www.caucho.com/download/ I used open source version.
  2. Unzipped the file.
  3. Went to the unzipped directory, selected lib/resin.jar and copied it to my projects war/WEB-INF/lib folder.
  4. 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.
  5. 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:
        <welcome-file-list>
            <welcome-file>index.php</welcome-file>
        </welcome-file-list>
       
        <servlet>
             <servlet-name>quercus</servlet-name>
             <servlet-class>com.caucho.quercus.servlet.GoogleQuercusServlet</servlet-class>
        </servlet>
       
        <servlet-mapping>
             <servlet-name>quercus</servlet-name>
             <url-pattern>*.php</url-pattern>
        </servlet-mapping>
  6. Next, I pasted this to war/WEB-INF/appengine-web.xml – again under the existing code:
        <static-files>
          <exclude path="/**.php"/>
        </static-files>
        <resource-files>
          <include path="/**.php"/>
        </resource-files>

    This is supposedly needed to make sure the .php files get processed by PHP and not served up as text.

  7. Then I added index.php to war/WEB-INF and simply put this in the file:
    <?php

        phpinfo();

    ?>
  8. Selected the project, Guestbook, on the top menu chose Run->Debug As->Web Application
  9. Finally, went to http://localhost:8888/index.php and marveled at the miracle.

5 Comments to “Running Quercus PHP on App Engine”

  1. By kevin, August 16, 2010 @ 12:05 pm

    Great explanation!

    I got this to work on my local machine, but when I upload it to GAE, it says the resin jar is too big.

    Any thoughts?

  2. By Raivo, August 16, 2010 @ 10:05 pm

    Did you try uploading your app from the command line with the –enable_jar_splitting option?

  3. By PHP on Google App Engine, October 29, 2010 @ 1:56 pm

    This helped me when creating a package for easy PHP application building on Google. Thanks! http://php-apps.appspot.com/

  4. By Danny, November 4, 2010 @ 10:55 am

    I was trying to deploy a php based application onto Google Appengine with the Quercus php engine.

    the basics worked (phpinfo() etc.) but my application had some trouble with the file_get_contents call which wouldn’t get the file. the error looked something like this:

    create_request.php:35: Warning: ./simplexml.txt cannot be read [file_get_contents]

    I was trying to access a file in the file system local to the script (not an external url).

    I’ve seen a couple of articles hinting at limitations with the php implementation (obviously db support is one thing) but nothing firm on support for file_get_contents or fopen.

    Is there a limitation for local file access? Are there any configuration options that block file access (I’m aware of the allow_url_fopen = On but nothing specific to local files)?

    thanks, Danny

  5. By Raivo, November 4, 2010 @ 8:53 pm

    @Danny: is the file in the war/WEB-INF folder? http://code.google.com/appengine/kb/java.html#readfile

    Also, seems like there was a bug with file_get_contents which should be fixed in v4.0.4 so I hope you are using the latest version.
    http://forum.caucho.com/showthread.php?t=3244

RSS feed for comments on this post. TrackBack URI

Leave a Reply