Run PHP on the Google App Engine

Google Appengine Running PHP

Google launched their Google App Engine (GAE) a year ago. The free hosting in App Engine is allocated 500 MB of persistent storage and enough CPU and bandwidth for about 5 million page views a month. Also, if you really want more you can see pricing plans.

GAE will support Java going forward. Unfortunately PHP support on the App Engine is still left as the top item in the wishlist. So until Google announces their official PHP support we have a workaround to run PHP using Quercus. Quercus is basically a 100% Java implementation of the PHP language (requires JDK 1.5).  Since the App Engine now supports Java this means we can use Quercus to run PHP scripts on the App Engine.

So all you need to use the GAE and run PHP
1) Register a free account.
2) Download this file to your computer.
3) Edit application XML tag in the file war\WEB-INF\appengine-web.xml to the name of the application you have registered.
4) Finally upload your application. I downloaded Google App Engine SDK for Java and use the following command in windows.
appcfg.cmd update C:\projects\phpwithjava\war

To see this in action just visit:
http://phpwithjava.appspot.com/webdigi.php and http://phpwithjava.appspot.com/info.php

NOTE: phpwithjava is my app name with GAE. Image by Aral Balkan.

Also read...

Comments

  1. hm2k said on :

    Is there a way to use a custom php.ini with this?

    Cheers.

  2. gnc said on :

    Thanks for sharing.
    But how do we get CURL to work with this?

  3. Peral Mariam said on :

    Nice post. Thanks.

  4. Omkar Khair said on :

    At this Google IO 2010, there were presentations I guess for running WordPress on GAE with help of Quercus. The say u could just modify the SQL queries according to the datastore.. Is there a specific tutorial for this process?

  5. Omkar Khair said on :

    Oops Sorry! It was Google IO 2009

  6. Webbie said on :

    Very informative and realy nice post. I have found your blog on google.

  7. David Nelson said on :

    @Tommy

    To get around the 1,000 file limit, you might try writing a script to put all the classes in your apis into a few very large files.

    David

  8. mtik said on :

    Nice post!
    But still need some more explanation.

  9. indieinvader said on :

    Why would you want to go through so many hoops to run *PHP*, it’s a horrible programming language! Not to mention that you have to run it in Java (another horrible programming language)

    — However, This is great for people who really want to run PHP with free hosting 🙂

  10. amateurluder nackt said on :

    Just wanted to say this is a super interesting post.

  11. PHP on Google App Engine said on :

    This blog guided me when testing and creating a package for easy PHP application building on Google. Similar approach with newer libraries you can find from: php-apps.appspot.com/

    I think PHP and Java is a good combination. Java for background logics and PHP for frontend UI generation.

  12. wowio said on :

    This is a good idea.

  13. TheBojda said on :

    When I started to use PHP on AppEngine, one of my biggest problem was the non-relational database access layer. I’ve developed a simple ORM framework, which supports GAE through the low level datastore API. If you interested, try it, the page of the project is code.google.com/p/lworm/

  14. Thomas said on :

    I have just tried it.
    Works fine….

    By the way, there’s a small copy and paste error in the index.html, it is twice the same link to info.php in the a-attribute.

  15. Hunter Dolan said on :

    OMG THIS IS THE BEST THING SINCE THE INVENTION OF COMPUTERS!!!! Where can I give you a donation? You just saved my project weeks of work!!!

  16. Pingback: PHP in Google App Engine

  17. SalmanAbbas007 said on :

    Nice Post. Thanks 😉

  18. John said on :

    I have a simple question- When I execute the command
    appcfg.cmd update C:\projects\phpwithjava\war, the file uploads successfully, WITHOUT asking for any authentication for my GAE account credentials, ie gmail id and password.

    With this anyone can upload files to my account if he has my Application ID, which is public. What am I missing here?

  19. Keerthi said on :

    This is fantastic… thanks a lot…

  20. Keerthi said on :

    If you encounter java.lang.ClassNotFoundException: `org.mortbay.jetty.handler.ContextHandler’ issue at the very first time you run sample app, try RELOAD your page.. it will disappear..

  21. Keerthi said on :

    Anyway refreshing page is not a solution for java.lang.ClassNotFoundException: `org.mortbay.jetty.handler.ContextHandler’ issue.

    1. Download jetty from jetty.codehaus.org
    2. Extract the archive.
    3. Copy 2 files jetty-6.1.26.jar / jetty-util-6.1.26.jar from jetty lib folder to your application’s lib folder (in WEB-INF).

  22. H. H. Sajjad said on :

    Thank you a dozen, I got it working.

  23. Phil said on :

    Instead of curl, I used this code:

    import java.net.URL;
    define(‘URLFetchServiceFactory’, new Java(‘com.google.appengine.api.urlfetch.URLFetchServiceFactory’));
    $data = URLFetchServiceFactory->getURLFetchService()->fetch(new URL([YOUR URL HERE]))->getContent();

    So far so good!

  24. Web SMS said on :

    Good information, But I try Upload my script free send sms from websmsonline.com/index.php to websmsonline.appspot.com/index.php Script not work. Hosting not support Curl

  25. Pierre said on :

    Hi,
    Thanks a lot for this article my php application is hosted on GAE. The only problem i have is with the CAPTCHA feature. I am using an open source solution called “Securimage” (phpcaptcha.org)
    i use another php to instantiate the class and show a CAPTCHA image. It was working on my local Apache server but it’s not working on GAE it just display the following message:
    Error: Server Error
    The server encountered an error and could not complete your request.

    If the problem persists, please report your problem and mention this error message and the query that caused it.

    Can someone help?? Thank you

  26. Alwyn said on :

    just go to php manuals you will get all there!!

  27. diyism said on :

    Thanks, i have use this for long time. My appengine-web.xml:

    <!– For PHP-Support –>
    <static-files>
    <exclude path=”/**.php” />
    <exclude path=”/**.inc” />
    </static-files>
    <resource-files>
    <include path=”/**” />
    </resource-files>

    </appengine-web-app>

  28. Pingback: Quercus (PHP on Google App Engine) is_file is_dir not Working | SeekPHP.com

  29. Deandra Getman said on :

    I think that is among the such a lot important information for me. And i’m satisfied reading your article. However wanna commentary on few common things, The website taste is great, the articles is truly excellent : D. Just right activity, cheers

  30. Pingback: Quercus (PHP on Google App Engine) is_file is_dir not Working

  31. Praveen said on :

    hii guys,
    Your solution to make php work on GAE has helped me.
    As such I am working to upload a file(image and .3gp) on GAE using upload.php
    in form tag.But I am having trouble in uploading the file, while upload.php is running fine
    my html code

    Filename:

    upload.php
    0)
    {
    echo “Error: ” . $_FILES[“file”][“error”] . “”;
    }
    else
    {
    echo “Upload: ” . $_FILES[“file”][“name”] . “”;
    echo “Type: ” . $_FILES[“file”][“type”] . “”;
    echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb”;
    echo “Stored in: ” . $_FILES[“file”][“tmp_name”];
    }
    ?>

    please help me with this problem…..

  32. Akshay Raje said on :

    Here’s a quick and dirty wrapper function I created for URL Fetch using PHP via Quercus on Google App Engine – stackoverflow.com/questions/7610294/fetching-a-file-from-a-php-file-in-google-app-engine/9382523#9382523

  33. rakibtg said on :

    is it possible to host a php email form?

  34. Pingback: The Web logix Blog » Blog Archive » Cloud Hosting/Storage Toolbox: Options & Tools

  35. Yousaf said on :

    Is this a stable solution or would it only work for basic implementations?

  36. Megha Agrawal said on :

    when i run command appcfg.cmd update …./war, getting following exception:

    Exception in thread “main” java.lang.UnsupportedClassVersionError: Bad version n
    umber in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
    4)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

    whats going wrong here?

  37. nathan said on :


    Hey,

    Your method works well if my php is in the root directory, e.g. under war

    If I create sub folder, then the php file will be downloaded instead.

    Any other method? Looking for a solution from someone

    Thanks.” …. try the following code in the appengine-web.xml file to fix this issue.

    true

  38. Game mobile said on :

    Can I use wordpress with GAE ?

  39. mrk said on :

    hello sir how to upload you script sorry but i am new and don’t know i try my best but fail to upload that script google app Engine required app.yaml so please help me how to upload this script with this command
    “appcfg.cmd update C:\projects\phpwithjava\war” its not working in cmd or appcfg.cmd i install python 2.7

Comments are closed.