Sunday, December 5, 2010

Host your Website - Google app engine

      Google app engine provides environment to host your web-application . Essential steps involved in hosting a website -
    1. Buy a domain name with no hosting space to pay for.(ex- GoDaddy)
      Buying a domain is simple we can go to any website and buy a domain .
Ex- GoDaddy , here you can get discount also some coupon are available on net.
    2 .Upload and configure your web application(website here) on Google apps
      Web Hosting ! this is where google app engine comes to rescue . Follow few of below simple steps to upload/deploy your website on app engine.
  1. Create app engine account, install python and download app engine sdk.  
  2. On your machine create a folder  eg. MyWebsite (c:\MyWebsite).
  3. Make a folder named static inside that eg. (C:\MyWebsite\static)
  4. keep all your files to be uploaded inside "Static".
  5. In "MyWebsite" we need to add a file app.yaml
Code to be written inside app.yaml
application: [Name of application , which you create on google app engine eg. Website]
version: 1
runtime: python
api_version: 1
handlers:
- url: (.*)/
  static_files: static\1/index.html
  upload: static/index.html
- url: /
  static_dir: static

Folder hire achy looks like this in genral case
- MyWebsite/
   -Static/
       -index.html
       -css/
       -JS/
       -images/
       -favicon.ico
   -app.yaml

      Once done with this on client side(i.e Your machine) , log in to google app engine and create simple application (eg Website). Now, we need to deploy our code on app engine . Open command line and type in simple command --appcfg.py --email=example@gmail.com update c:\MyWebsite/
Done ! now your website is hosted on google app engine and can be accessesed directly at 
url- http://[Your-Application name eg. Website].appspot.com/
    3. Management of Domain, Domain Mapping (as google app dosen't allow you to map to naked domain eg example.com, you may map to sub-domain though eg- test.example.com )
      Application is up and running but generally we want it to map to our domain eg. example.com .Since app engine dosen't allows that so we have to follow few workarounds to make it work as we wish. 

Domain Setting
Domain Verification-
   - Go to Google App engine Dashboard-> Your Application[eg. Website here]
   - Administration->Application Settings-> Add Domain 
   - Enter your Domain Name and follow registration process and Get domain registered.
   - Go To Google Apps for your domain name 
   - Login to dashboard
-  Go to Domain setting and check for domain registration etc. 





URL Mapping
- Browse to Service Setting, go to your app eg-Website here 
- Add new URL for your google app
- Here we can't map to naked domain like example.com
So , as matter of practice we map it to www subdomain eg- http://[www].example.com
(as www.example.com is also a subdomain of example.com)


 
After this our website will be available at http://www.example.com and [your application name eg. website].appspot.com . Content available at subdomain http://www.example.com will not be available at naked domain http://example.com .

To make content available at http://example.com we need to redirect it to http://www.example.com. For this , we can use meta refresh but this is not a good practice . One of alternate solution is using header redirection. Generally, at domain provider we are given a small space of web hosting ,there we have to put a index.php file with following code inside it
header ("Location: http://www.example.com");
This solves our problem and our website gets redirected properly.So now the app/website is available at - 
- http://[Your application name].appspot.com
- http://www.example.com
- http://example.com
This is a simple way of keeping your domain name and web hosting a separate . Incured with flexibilities of Google App Engine, your website will be 99.9% up as claimed by Google.

Cheers!