Run PHP on the Google App Engine
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.
Is there a way to use a custom php.ini with this?
Cheers.
Thanks for sharing.
But how do we get CURL to work with this?
Nice post. Thanks.
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?
Oops Sorry! It was Google IO 2009
Very informative and realy nice post. I have found your blog on google.
@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
Nice post!
But still need some more explanation.
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 🙂
Just wanted to say this is a super interesting post.
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.
This is a good idea.
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/
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.
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!!!
Pingback: PHP in Google App Engine
Nice Post. Thanks 😉
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?
This is fantastic… thanks a lot…
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..
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).
Thank you a dozen, I got it working.
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!
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
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
just go to php manuals you will get all there!!
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>
Pingback: Quercus (PHP on Google App Engine) is_file is_dir not Working | SeekPHP.com
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
Pingback: Quercus (PHP on Google App Engine) is_file is_dir not Working
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…..
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
is it possible to host a php email form?
Pingback: The Web logix Blog » Blog Archive » Cloud Hosting/Storage Toolbox: Options & Tools
Is this a stable solution or would it only work for basic implementations?
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?
”
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
Can I use wordpress with GAE ?
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