Run PHP on the Google App Engine

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

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

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


 
Sandeep
Mar 2, 2010 at 2:07 pm

Has anyone got CURL working on GAE?


 

Reply

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