Tuesday, March 3, 2015

Create a web application/website on Google Cloud

Creating your own website or web application is a cool thing, there are several ways you can get this done. The first thing is a domain name, that is the name or label of the website something like google.com, microsoft.com or yahoo.com. Right now, create a website is pretty easy, you don't need to have any hardwares such as a workstation, lighting-fast cable, router and so on.

Let's start from the first stuff you need, the domain. There are many companies which you can purchase a domain name. Here are some very popular companies for registering your domain, such as namecheap.com, godady.com, 1and1.com, whois.com. The domain name you want to register is the one which is not registered yet by anyone. All the domain registration websites can check if the domain name you choose is already registered or not.

After get the valid domain name, you could go ahead to find a place where you can create a website. Most of the domain registration websites have the packages for domain purchasing, they usually supply a friendly graphical user interface to create a website. The price are variable between companies, you may need to shop around to find a good package for your requirements. Now, the cloud technology is very popular, most of the web hosting are based on the cloud platform. Some big companies are not only give a cloud platform, and give you a lot of features and services. Amazon AWS(Amazon Web Services) platform will give you accessing to their web services. The first year on amazon is free, but next year you may get a big bill. Google Cloud platform is another good choice. The first 3 months or two months are free, that depends on the package or products you choose. After the free trial, you can select to stay in Google or move to another platform or company, if you can backup all the data and files. Anyway, there are two to three months free trial, and after that the bill may as low as $2/month. So why not take a look to see if it's a good place to host my stuff.

Joining the Google Cloud platform are pretty simple, open the http://cloud.google.com and select one of the products like Compute Engine and then click on 'Start your free trial'. And then follow the page flow to finish the registration, the credit card information is needed but it won't charge you anything for now. After the registration, on the left side there are a bunch of menu items like most of web applications, select the 'Compute'->'Compute Engine'->'VM instances'. There will be an link or button for 'Google Compute Engine Tutorial', click on that. It will guide you to create your first back-end and front-end instance with an example. It's a good way to get start with Google cloud platform and understand how it works.

The basic tutorial steps looks like these:

  • Create back-end instance, back-end means something like a database server.
  • create front-end instance, front-end means application server/web server.
  • Install and run the back-end database
            Enter these commands to install and run MongoDB. You can use the keyboard to copy and paste each command line. Click Done when you finish entering all the commands to close the SSH window.

            Update packages and install MongoDB. When asked if you want to continue, type 'Y'.
            sudo apt-get update
            sudo apt-get install mongodb
            The MongoDB service started when you installed it. You must stop it so you can change how it runs.
            sudo service mongodb stop
            Create a directory for MongoDB and then run the MongoDB service in the background on port 80.
            sudo mkdir $HOME/db ; sudo mongod --dbpath $HOME/db --port 80 --fork \
            --logpath /var/tmp/mongodb
            After you enter the final command, click Done and then confirm that you want to leave the page to close the SSH browser window.

  • Install and run the web app on your front-end VM
            Enter these commands to install the todo web application. You can use the keyboard to copy and paste each command line. Click Done when you finished entering all the commands to close the SSH window.
            Update packages and install git, NodeJS and npm. When asked if you want to continue, type 'Y'.
            sudo apt-get update
            sudo apt-get install git nodejs npm
            Clone the sample application and install application dependencies.
            git clone https://github.com/GoogleCloudPlatform/todomvc-mongodb.git
            cd todomvc-mongodb;npm install
            Start the todo web application. Note: The IP addresses below are internal IPs for communication between servers. You can find these IP addresses on each server’s details page.
            nohup nodejs server.js --be_ip 10.240.253.122 --fe_ip 10.240.2.76 &
            After you enter the final command, click Done and then confirm that you want to leave the page to close the SSH browser window.


But there is a little problem on step 'npm install'. If you just follow the instructions, you will get the following error message on step 'cd todomvc-mongodb; npm install'.
    npm WARN package.json mongoose@3.6.20 bugs.email field must be a string email. Deleted.
To fix this problem, first thing is making sure you are in the directory 'todomvc-mongodb' on the SSH window. If not, just navigate to the directory by 'cd todomvc-mongodb', and then use the command 'vi package.json' to edit the file package.json. On the line 10 change the content from
       "mongoose"   : "~3.6.2",        to            "mongoose"   : "~3.8.1",
And then rerun the command 'npm install', it will work fine. At the end of the tutorial, you should see your sample page like this.


Congratulations! You have finished the first sample on Google Cloud.

3 comments: