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.
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.
Hi
Thanks for this post.
@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.
Pingback: You can run PHP on Google App Engine | Lacisoft's
I run your example. It works fine, thanks. But what about apache url rewriting. Is there any way to implement this?
Thanks!
Pingback: Aral Balkan - How to run PHP on Google App Engine
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 🙂
Interesting. Any ideas about performance on PHP via Java?
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.
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.
Pingback: Google App Engine si PHP | My Binary Life
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.
Good job….
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.
Good! Will try it later.
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.
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
How can I use the datastore api inside PHP ?
How about mod_rewrite?
Pingback: Caucho Technology » Blog Archive » Quercus on the Google App Engine
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
Very interesting post…will try it tomorrow…
Pingback: » PHP con Google App Engine
Can we use jsp in Quercus … how can we handle data base operation using java php under quercus please give us example.
Thanks,
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,
Hi, I have started a blog about running PHP on Google App Engine, blog.herbert.groot.jebbink.nl
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?
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.
How to install WordPress on Google App Engine: digg.com/d1sZjZ
@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/
@Herbert Groot Jebbink, thanks man, but why isn’t this described at the very start of this post?
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~
good job 🙂
Pingback: PHP, Web and IT stuff » Blog Archive » Get your own cloud server running in 15 minutes
JIQL, the JDBC Wrapper for Google DataStore, integrates with Quercus.
So you can run PHP applications with your same SQL queries.
Amazing!
Does anybody know how to access database with php or is there any documentation.
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
Damn, that sound’s so easy if you think about it.
Sorted, Thanks.
Thanks for your insights.
Thanks 🙂
Got it! Thank you.
nice job, many thanks.
Done. Next step is to setup the database also.
I just added my new google app. thanks for the details.
fantastic.. So much for only python and java support.
Great work. Thanks for sharing.
Thanks a million!!!!
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
This works for ALL PHP scripts I have tried. Please try this on PHP5. I have not tested it.
Thanks a lot !
great job putting this info together, works a treat, cheers!
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.
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.
It seems a lot of php functions result in 500 server error. Anyone have ideas on opening the library a bit more?
Hi thanks a lot for this… I also managed to run CURL on GAE with this!
Thank you, supper cool post.
Ruby is also available through JRuby on Google App Engine
(http://code.google.com/p/appengine-jruby)
I managed to run and get almost everything working quickly.
@ Seenu – Can you please tell me how you got CURL running?
Yeah, please do tell how to use curl with Quercus/PHP 🙂 Thanks!
Yes, tell me also!
OK, that seems to be a joke 🙂 I have read all the Google info and found nothing…
Yes @Nikki is right. @Seenu you have to share the curl code to prove yourself right! 😉
Please plzzz share the curl code ……………..
I want run wordpress on GAE
Saw your site bookmarked on Reddit. I love your blog contents. Your site has been very useful for me.
it is good and works for me.
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
Has anyone got CURL working on GAE?
Thanks for sharing this information….
Thanks for sharing this information…
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?