How to run PHP on Google APP Engine

To have php run on GAE you need Quercus, though the name appears some difficult the process is much simple than expected, you just need to add few jar files change some settings and thats it..you will have your php code running on google app engine

The biggest problem during the whole process is to get the exact jar files

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.

Now the actual process starts.

Step -1 Edit Web.xml file to have following lines of code

<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<init-param>
<param-name>ini-file</param-name>
<param-value>WEB-INF/php.ini</param-value>
</init-param>
</servlet>

and

<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>

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.

Next on the list is appengine-web.xml. Add the following code right after closing of system-properties tag

<static-files>
<exclude path="/*.php" />
</static-files>
<resource-files>
<include path="/**.php" />
</resource-files>

Next to create one php.ini file in war/WEB-INF folder. Currently i kept it blank.

Now the final step is to create some php files to check. I created simple file that echo phpinfo to check php running fine at location war/index.php

Initially when I tested this out I was getting a strange error about org.mortbay.util.ajax.Continuation not found.  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 or required by Quercus

Now that’s it  I included that jar and my php started working on local instance of GAE application

I deployed on app engine, and there too it started smoothly.

Live Example

Github Hosted Project

Advertisements

How to connect your Android app to local instance of Google APP Engine on Android Emulator

Couple of days I am searching for the solution to get the local instance of google app engine to my android app on emulator. This is required as every time you cant deploy the GAE app version to check as its time consuming and not advisable.

To set up this its assumed that you have setup google app engine local instance and your android application

If you are trying, from your Android application through the Android emulator, to access an external service on the same computer (such as your own Google App Engine site) by using the host name localhost or the IP-address 127.0.0.1, you might get a java.net.ConnectException: localhost/127.0.0.1:8888 – Connection refused error – even though you can perfectly well access the service outside the Android application.

 

The reason why a ConnectException occurs is because localhost or 127.0.0.1 inside the Android emulator is the emulator’s own loopback interface, meaning all request sent to the destination will be looped backed to the emulator and won’t actually be sent to your local machine.
To by pass this, simply replace localhost with the IP-address 10.0.2.2as this is a special address towards the real local host.
thats it  and you can now access the your local GAE instance with Android app.