Thursday, 11 December 2014

Quickstart: First Steps with Google Compute Engine - Launching an Apache Web Server

I have been playing with Google Compute Engine (from here on called GCE) for about 2 months now and I have come to the decision of creating a quickstart tutorial for GCE. There is already one in the GCE docs but it requires you to download the SDK and misses out some steps (indicated later) but I will take a different approach with everything being done in the browser, no SDK to be downloaded.

Just in case you got here without having a clear understanding of what GCE is all about, here is Google's definition of GCE which I think should be clear enough.

Google Compute Engine is a service that provides virtual machines that run on Google infrastructure. Google Compute Engine offers scale, performance, and value that allows you to easily launch large compute clusters on Google's infrastructure. There are no upfront investments and you can run up to thousands of virtual CPUs on a system that has been designed from the ground up to be fast, and to offer strong consistency of performance.
 Now lets get to hacking !.

First you have to create a Google account (if you already have a Gmail account, you're good to go). Visit to sign in to the cloud console or create an account if you don't have one. As of now Google gives $300 cloud credit and note that you need to have a credit card to receive this though its not real money. I am using the cloud credit for this tutorial.

If you have signed in and gotten your credit, then head to the cloud console if not automatically redirected there by heading to . Assuming you are new to the Google Cloud Platform, you should not see any listed projects

As in the screen shot below you should see a "Create Project" button. Use it to create a new project. You will be asked to give a Project name, which can be anything you like and a Project ID which should be unique and is used as the domain for your project if you use AppEngine hence the same rules that go for choosing a domain name apply.

After your project is opened, select compute on the left navigation bar and go to 
Compute->Compute Engine->VM Instances. It should not show much since its your first time with GCE I assume. Click the "New Instance" button to create a new Virtual Machine (VM).

You will have to fill in some information.
Name - The name you want for your VM  
Metadata - [optional] Used to add info about your VM which can be used by startup scripts and lots more. Skip this for now.
Firewall - You will need to check http and/or https since we are setting up a web server. (If in future you intend to create an app which does not serve trafic then you can leave this unchecked) 
Zone - This is the location of you VM. 

Machine type - Select the type of machine you want according to your needs 
Image - The operating system you want. For this tutorial, use ubuntu-1404-trusty-... 
Networking - If you choose Ephemeral for external IP, your IP will change each time your VM restarts but they are easier to create.

Create the VM and lets get to the interesting stuff.

In your list of VMs (you should have just one VM if you have been following this tutorial) you will see the SSH button on the right side of each VM item. Click it to load up a browser based command line.

Enter the following commands to install apache

me@my-first-instance$ sudo apt-get update
me@my-first-instance$ sudo apt-get install apache2

You should head back to where you had your VMs listed, copy the external IP and insert it into your browser to view the Apache default home page which may look like this:
Your web server is up and running.

Don't forget to leave your thoughts, questions and/or corrections in the comments section.

Learn more about GCE from the official documentation