The task here is to setup an Amazon EC2 instance and run the Ghost blogging application. Basically, I wanted to create this blog, that your viewing now, on Amazon EC2 and use my GoDaddy domain name. This will be a two part blog where the first part will be setting up EC2 while the second part will be Amazon Route53 setup using GoDaddy as the registrar. I thought this was going to be an easy setup, however, I thought wrong. The were a few gotchas that really held me up, so I hope this document helps anyone having issues setting up Ghost blogger on EC2. This step by step process will be a document for anyone having this issue or plans to do the same configuration as I.
Basically Elastic IP is synonymous with a static IP, as it doesn't change when you restart your instance so you can always refer to the same IP address in applications and not worry about them changing.
First things first, you are going to need to start up an EC2 instance. I am still on the free tier for EC2, so I use the micro instance with 8GB of space locally stored. For the purposes of these instructions we will be using the Amazon Linux AMI. If you are not familiar with this setup please refer to Amazon documents. I will not go over creating key pairs and how to SSH into your instance I will just cover what to do when SSH'd into your instance. So let's start from there.
Now when you have the environment you wanted setup lets SSH into the instance using the pem key you created with a key pair. Once you have connected, your first command in the console should be the following to update all of the installed packages on the server.
Next we need to export the port which will be used to handle http traffic. The reason we need to do this is because Amazon Linux reserves port 80 for http traffic and the first 1,000 ports are reserved for root access in general therefore we cannot bind our Ghost Node server to that port as a normal user. To do this we will first edit a file within our ec2-user's home directory to set an environment variable for the port that we will be using.
Next we need to redirect incoming requests on port 80 (http) to our recently exported port (8080).
And thats is it. You now have all http traffic feeding right into our node server hosted on port 8080. Next is installing GCC compiler.
You can download prebuilt a pre-built for Linux NodeJS binary or you can retrieve the source code and build it yourself. For this exercise we will build Node from source and this requires a gcc compiler to be installed on your machine because Node will be built to generate the binary files necessary for running it. Dont let this scare you as we will just use a simple yum command to download and install for everything required.
NOTE: You can also use git and clone the NodeJS repo and then checkout the necessary branch, but I figured this was a lot easier to explain to someone who is not familiar with git.
This takes a very long time, sometimes up to 20 minutes, so go do something productive instead of watching water boil on your screen. After Node has finished building, its now time to install it.
You can confirm that the build and install was successful and resulted in the binary being installed where expected with the following.
Now save and exit. To 'refresh' this file for the OS to use we must first source it with source .bash_profile. For a sanity check try running node -v and this should return the version of your file. Another good thing to check is to see if you have the Node Package Manager(NPM) which should come with NodeJS within the download. To check its within your path just do the following.
If that command returns the npm version we are all set to download and install Ghost.
Now we need to do a few things done before we can start up Ghost. I am just going to list the few commands that I performed to organize and unzip. Now I performed these commands while in my home directory, but you could install Ghost where ever pleases you.
Note the --production as this only downloads the production dependencies and not the development or test ones.
Now we need to change some config options that come with Ghost out of the box. Copy the config.example.js file found in the Ghost distribution to config.js and then open up ~/ghost/config.js with your favorite editor.
Now time to start Ghost.
Now this will be hosted on the Elastic IPs address, however, that is ugly and not very effective for people to get to. To see the Ghost Blogger's home page just navigate your browser to your ElasticIP address. So in the second part of this blog I will show you how to use Amazon's Route53 and GoDaddy to be able to use your domain name instead of IP.