Run PHP on the Google App Engine

Posted by php-manual on Apr 13, 2009 in PHP Development |

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.

Tags: , , ,

101 Comments

Unreality
Apr 14, 2009 at 7:10 am

anyway for the php to access any kind of database. – I know that Memcached is provided by GAE so we can use that by simply adding a key value pair.


 
Chris
Apr 14, 2009 at 10:18 am

Hi

Thanks for this post.


 
Strolling on web
Apr 14, 2009 at 10:55 am

@Unreality
Google App Engine’s datastore has a SQL-like syntax called “GQL”. Select statements in GQL can be performed on one table only. GQL intentionally does not support the Join statement, because it is seen to be inefficient when queries span more than one machine. Instead, one-to-many and many-to-many relationships can be accomplished using ReferenceProperty().This shared-nothing approach allows disks to fail without the system failing.
The where clause of select statements can perform >, >=, <, <= operations on one column only. Therefore, only simple where clauses can be constructed. Switching from a relational database to the Datastore requires a paradigm shift for developers when modeling their data.
App Engine limits the maximum rows returned from an entity get to 1000 rows per Datastore call. Most web database applications use paging and caching, and hence do not require this much data at once, so this is a non-issue in most scenarios.[citation needed] If an application needs more than 1,000 records per operation, it can use its own client-side software or an Ajax page to perform an operation on an unlimited number of rows.
Unlike a relational database such as Oracle, Microsoft SQL Server, MySQL, or PostgreSQL, the Datastore API is not relational in the SQL sense.


 
You can run PHP on Google App Engine | Lacisoft's
Apr 14, 2009 at 11:28 am

[...] seems that some people figured out how to run PHP on Google App Engine.  You may be wondering how this is possible as Google doesn’t support PHP on App Engine. [...]


 
Charles Alves
Apr 14, 2009 at 2:05 pm

I run your example. It works fine, thanks. But what about apache url rewriting. Is there any way to implement this?

Thanks!


 
Aral Balkan - How to run PHP on Google App Engine
Apr 14, 2009 at 2:07 pm

[...] go to Roshan Abraham who alerted me to this via email today. The How to run PHP on Google App Engine article by Aral [...]


 
jQuery Howto
Apr 14, 2009 at 2:49 pm

I was wondering if this is possible… It seems it is :)

@Unreality, Still, you are getting PHP on App Engine! It’s better then nothing… For those developers that don’t want to learn the whole new language this will do for now… :)

PS. They can get another free hosting you might argue :)


 
Ozh
Apr 14, 2009 at 5:45 pm

Interesting. Any ideas about performance on PHP via Java?


 
mkv
Apr 14, 2009 at 8:38 pm

Java-compiled PHP performance seems to faster than standard PHP (at least PHP without any accelerators). One must understand that querqus is NOT interpreting PHP but compiling PHP to Java classes that will be run at servlet speeds. Moreover, one gets the benefit of using more advanced PHP techniques that further speed up things.


 
Arto Liukkonen
Apr 15, 2009 at 4:47 am

Nice post, just had one problem that I got fixed with few tries. When editing war\WEB-INF\appengine-web.xml for application name, notice that application name MUST be in lowercase. For example I created application called “Feedlar”, but if I tried to upload that it hit me with “No permission”. When changed xml config to “feedlar”, it worked like charm.

Tried to get php-txt-db work with no luck (getting only error 500). Maybe we just have to wait for official php support to get everything work, but for now Appengine can be used as free hosting for simple php applications that doesn’t require database.


 
Google App Engine si PHP | My Binary Life
Apr 15, 2009 at 5:28 am

[...] nu am stiut cu ce se mananca pana azi (e drept ca nici nu m-a interesat), dar azi am dat peste un articol despre rularea aplicatiilor PHP pe aceasta platforma si deci… am aflat In principiu Google [...]


 
diablonhn
Apr 15, 2009 at 6:56 am

Quercus’ pretty fast. Here’s a whitepaper on its performance:

caucho.com/products/whitepapers/quercus.pdf

The open source Quercus version runs in interpreted mode. As far as I can tell, interpreted mode is 10-20% slower than compiled mode. Nevertheless, it’s still faster than regular PHP.


 
Dafei
Apr 15, 2009 at 7:13 am

Good job….


 
taviroquai
Apr 15, 2009 at 8:31 am

With Java everything is possible…

Maybe this is why GAE administration has left PHP support aside from the beginning… This is a way to “impose” Java to the developers community besides Python.


 
Gan
Apr 16, 2009 at 1:57 am

Good! Will try it later.


 
Howard
Apr 16, 2009 at 8:33 am

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.


 
Manuel Arwed Schmidt
Apr 17, 2009 at 5:38 pm

There was a misconfiguration in the first posted apps, you must edit appegine-web.xml in /war/WEB-INF/ so something like this:

heypasteit.com/clip/58J

I’m not good at regular expressions, so I’ve cheated a little bit. You’ll see when looking the XML.

- Arwed


 
Edmar
Apr 21, 2009 at 2:51 pm

How can I use the datastore api inside PHP ?


 
blkk
Apr 28, 2009 at 4:23 pm

How about mod_rewrite?


 
Caucho Technology » Blog Archive » Quercus on the Google App Engine
Apr 28, 2009 at 4:54 pm

[...] Google App Engine and what its possibilities are for Quercus. Some folks from a PHP shop in Britain got Quercus running, but the version they were using was pretty old and seemed to come from a bizarre cross slice of [...]


 
Tuan Nguyen
May 6, 2009 at 4:26 am

Dear All,

Can anyone tell me: how is about data layer on GAE? As far as I know Google uses persistence objects ( DataNucleus Access Platform) So how do you use the platorm in PHP code?

Please advise me


 
Ruggero S
May 11, 2009 at 11:13 pm

Very interesting post…will try it tomorrow…


 
» PHP con Google App Engine
May 13, 2009 at 11:51 am

[...] Run PHP on the Google App Engine [...]


 
Gampesh
May 21, 2009 at 8:57 am

Can we use jsp in Quercus … how can we handle data base operation using java php under quercus please give us example.

Thanks,


 
Gampesh
May 21, 2009 at 9:37 am

Actually i wanted to make a google app engine application in php using Quercus but how can i do in jsp that i don’t know, the example you have given is not dealing with database connection, so could you please explain how can we make GAE app in php+java with Quercus support which also deal with database (JDO).

Thanks,


 
Herbert Groot Jebbink
May 27, 2009 at 1:16 pm

Hi, I have started a blog about running PHP on Google App Engine, blog.herbert.groot.jebbink.nl


 
Tommy Tam
May 30, 2009 at 6:10 pm

Has anyone else run into the problem of number of files >1000 exceeding the quota? With PHP, you can easily have more files because you might include some libraries. I found that I can’t port an existing application to GAE because of the 1000 file limit. Any suggestion?


 
Stefan
May 31, 2009 at 10:04 am

Hey, please advice, I can’t get this work. What folder do I have to upload and at what level in my application?, do I have to upload the entire “phpwithjava” folder in the root of my application?, just the “war” folder or just the “Web-inf” folder.

My app is called publicame, inside (at root level) I have the .py and .yaml files.

Any help is much appreciated.


 
Caucho Blog
May 31, 2009 at 4:15 pm

How to install WordPress on Google App Engine: digg.com/d1sZjZ


 
Herbert Groot Jebbink
Jun 1, 2009 at 8:23 am

@Stefan, if you have .py and .yaml files then you are working with the Python version of GAE. For PHP you need the java version of GAE. Do the Java Getting Started tutorial and then it is clear where to put the files to get PHP running.

code.google.com/appengine/docs/java/gettingstarted/


 
Stefan
Jun 1, 2009 at 3:24 pm

@Herbert Groot Jebbink, thanks man, but why isn’t this described at the very start of this post?


 
TaoGOGO
Jun 13, 2009 at 4:42 am

but!!!!! it seems that no one know how to use the database api!!!!!is anyone can tell us?if i can only read by php,i don’t think it’s useful than using jsp or python~


 
John
Jun 25, 2009 at 5:01 am

good job :)


 
PHP, Web and IT stuff » Blog Archive » Get your own cloud server running in 15 minutes
Jun 29, 2009 at 10:57 am

[...] take a look at the Windows Azure, Force.com or the Google App Engine which runs Java, Python and PHP using Quercus for free (certain usage limits [...]


 
Gabe Wong
Aug 3, 2009 at 4:47 pm

JIQL, the JDBC Wrapper for Google DataStore, integrates with Quercus.
So you can run PHP applications with your same SQL queries.


 
Rubel
Aug 19, 2009 at 5:43 am

Amazing!
Does anybody know how to access database with php or is there any documentation.


 
ram
Aug 24, 2009 at 5:59 pm

If I have a legacy php5 application developed, how much modifications required to make it work inside google app engine.

is app engine for developing new apps or existing projects also ?

Thanks


 
Rouletta-Bertram
Aug 24, 2009 at 7:16 pm

Damn, that sound’s so easy if you think about it.


 
John Gareth
Aug 26, 2009 at 2:31 pm

Sorted, Thanks.


 
Dean Jerpseth
Aug 26, 2009 at 2:31 pm

Thanks for your insights.


 
Sander Rietveld
Aug 31, 2009 at 10:20 pm

Thanks :)


 
antyfreeman
Aug 31, 2009 at 10:20 pm

Got it! Thank you.


 
JOYCE SMITH
Aug 31, 2009 at 10:21 pm

nice job, many thanks.


 
Robert Snead
Aug 31, 2009 at 10:21 pm

Done. Next step is to setup the database also.


 
Timothy Nimmons
Aug 31, 2009 at 10:21 pm

I just added my new google app. thanks for the details.


 
Good Sam
Sep 1, 2009 at 7:34 am

fantastic.. So much for only python and java support.


 
ANDY MOATS
Sep 1, 2009 at 7:35 am

Great work. Thanks for sharing.


 
Prakash
Sep 7, 2009 at 2:54 am

Thanks a million!!!!


 
Anna
Oct 24, 2009 at 9:20 am

Hey Prakash,
it seems like you got it, can you please help me install my app on GAE? anyhelp will be great, it#s an opensource rss php reader. Thanks in advance


 
Atila
Nov 6, 2009 at 10:00 am

This works for ALL PHP scripts I have tried. Please try this on PHP5. I have not tested it.


 
Wong
Nov 9, 2009 at 4:16 am

Thanks a lot !


 
markus aurelius
Nov 14, 2009 at 1:11 am

great job putting this info together, works a treat, cheers!


 
gustavo c
Dec 2, 2009 at 2:22 pm

Nice post, I share my experience with Ubuntu Linux.
I changed: appcfg.cmd update C:\projects\phpwithjava\war
for : appcfg.sh update my_path/phpwithjava/war
Thank you very much.


 
Madhu
Dec 4, 2009 at 9:34 am

As given in the one of the post- If an application needs more than 1,000 records per operation, it can use its own client-side software or an Ajax page to perform an operation on an unlimited number of rows.


 
film42
Dec 4, 2009 at 4:03 pm

It seems a lot of php functions result in 500 server error. Anyone have ideas on opening the library a bit more?


 
Seenu
Dec 11, 2009 at 1:39 pm

Hi thanks a lot for this… I also managed to run CURL on GAE with this!


 
Haggai Shachar
Dec 25, 2009 at 5:15 pm

Thank you, supper cool post.
Ruby is also available through JRuby on Google App Engine
(http://code.google.com/p/appengine-jruby)


 
Diana
Jan 9, 2010 at 5:58 pm

I managed to run and get almost everything working quickly.
@ Seenu – Can you please tell me how you got CURL running?


 
Marko
Jan 11, 2010 at 3:39 pm

Yeah, please do tell how to use curl with Quercus/PHP :) Thanks!


 
Niki
Jan 17, 2010 at 9:45 am

Yes, tell me also!


 
Niki
Jan 22, 2010 at 3:42 pm

OK, that seems to be a joke :) I have read all the Google info and found nothing…


 
Marion Janet
Jan 22, 2010 at 5:10 pm

Yes @Nikki is right. @Seenu you have to share the curl code to prove yourself right! ;)

Please plzzz share the curl code ……………..


 
Ango Yang
Jan 28, 2010 at 9:56 am

I want run wordpress on GAE


 
Kegan Jones
Feb 17, 2010 at 9:29 am

Saw your site bookmarked on Reddit. I love your blog contents. Your site has been very useful for me.


 
Marion
Feb 23, 2010 at 8:16 am

it is good and works for me.


 
conan
Mar 1, 2010 at 8:31 pm

i don’t get it….

do u mean change the contents inside the “appengine-web.xml” file?

if so, where do i change(let’s say my application is ‘good’) ?

phpwithjava
1


 
Sandeep
Mar 2, 2010 at 2:07 pm

Has anyone got CURL working on GAE?


 
Digisha Modi
Mar 22, 2010 at 10:56 am

Thanks for sharing this information….


 
Digisha Modi
Mar 22, 2010 at 10:56 am

Thanks for sharing this information…


 
Marcus
Apr 6, 2010 at 10:31 pm

Hey, I’m trying this out, and I am getting the error: “com.caucho.quercus.QuercusModuleException: java.lang.NoClassDefFoundError: java.net.Proxy is a restricted class. Please see the Google App Engine developer’s guide for more details.”

I’m using the Facebook API, and it seems to be the connecting to Facebook that is killing it.
A simple PHP script will working.
Is there any way to fix this?


 
hm2k
Apr 12, 2010 at 10:49 am

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

Cheers.


 
gnc
May 7, 2010 at 12:19 am

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


 
Peral Mariam
May 29, 2010 at 9:16 am

Nice post. Thanks.


 
Omkar Khair
Jun 1, 2010 at 8:58 am

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?


 
Omkar Khair
Jun 1, 2010 at 8:59 am

Oops Sorry! It was Google IO 2009


 
Webbie
Jun 8, 2010 at 6:15 am

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


 
David Nelson
Jun 14, 2010 at 5:04 am

@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


 
mtik
Jul 23, 2010 at 5:41 am

Nice post!
But still need some more explanation.


 
indieinvader
Oct 16, 2010 at 11:32 pm

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 :)


 
amateurluder nackt
Oct 27, 2010 at 8:00 pm

Just wanted to say this is a super interesting post.


 
PHP on Google App Engine
Oct 29, 2010 at 7:03 pm

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.


 
wowio
Nov 11, 2010 at 1:21 pm

This is a good idea.


 
TheBojda
Nov 19, 2010 at 9:06 pm

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/


 
Thomas
Nov 23, 2010 at 4:12 pm

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.


 
Hunter Dolan
Jan 8, 2011 at 2:05 pm

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!!!


 
PHP in Google App Engine
Jan 14, 2011 at 2:06 am

[...] Quercus is a pure java implementation of php and it allows us to run php code in app engine. Some really smart people figured out how to make it work. Check out brian and webdigi. [...]


 
SalmanAbbas007
Feb 23, 2011 at 11:36 pm

Nice Post. Thanks ;)


 
John
Mar 1, 2011 at 10:02 pm

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?


 
Keerthi
Mar 24, 2011 at 5:50 am

This is fantastic… thanks a lot…


 
Keerthi
Mar 24, 2011 at 6:28 am

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..


 
Keerthi
Mar 24, 2011 at 7:43 am

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).


 
H. H. Sajjad
Apr 6, 2011 at 8:15 am

Thank you a dozen, I got it working.


 
Phil
May 19, 2011 at 2:10 pm

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!


 
Web SMS
Jul 6, 2011 at 12:02 pm

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


 
Pierre
Aug 26, 2011 at 12:34 am

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


 
Alwyn
Sep 13, 2011 at 4:20 pm

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


 
diyism
Oct 12, 2011 at 5:52 am

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>


 
Quercus (PHP on Google App Engine) is_file is_dir not Working | SeekPHP.com
Oct 14, 2011 at 9:22 am

[...] have a PHP application running on Google App Engine, who has the ability to run PHP on GAE via Quercus. However, I notice that my scripts choke on GAE when they run an is_dir() or is_file() function. [...]


 
Deandra Getman
Oct 18, 2011 at 2:34 pm

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


 
Quercus (PHP on Google App Engine) is_file is_dir not Working
Oct 22, 2011 at 5:30 am

[...] have a PHP application running on Google App Engine, who has the ability to run PHP on GAE via Quercus. However, I notice that my scripts choke on GAE when they run an is_dir() or is_file() function. [...]


 
Praveen
Feb 6, 2012 at 12:13 pm

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…..


 

Reply

Copyright © 2012 PHP, Web and IT stuff All rights reserved. PHP Web development in London.