How to drive your Ghost blog using Continuous Delivery - Part One

Before we begin, this blog post is part of a 3-part series. You can read the all three blog posts here:

Part 1: How to drive a Ghost Blog using Continuous Delivery

Part 2: How to drive a Ghost Blog using Continuous Delivery

Part 3: How to drive a Ghost Blog using Continuous Delivery

I've written a few blogs before mainly using Wordpress, however, I've become a bit jaded with it. Wordpress is great if you don't ever want or have a need to touch the Themes and customise it but it's a total nightmare if you want to adapt a theme you've purchased. Not to mention if you mess any configuration up. You end up having to hack the mysql database metadata in the background - trust me it's not pretty. Wordpress is old hat these days, I mean embedding PHP code with HTML views - horrendous. Also, it's written in PHP (let me just pull out my special "Nuke it from orbit" button). Don't get me wrong Wordpress has it's place but when you want to customise your blog absolutely and have full control it's probably not your best option.

So, this time I opted to steer well clear and went for Ghost instead.

So why Ghost?

Excellent question! Partly because I thought it would give me a nice opportunity to play with Javascript and Node.js which I'm currently working with. On top of that it's super quick and lightweight. I hope you noticed just how quick the blog is to load even on poor connections. Let me know if you had issues loading the site up.

This is going to be an epic blog post so I'm splitting it in 3 to make it more digestable. First I'll tackle choosing your webhost

Choosing a web host

At the time of writing Amazon are offering free-tier for a year which means you get 750 hours for free for a t2.micro instance which is their most basic EC2 server. It should suffice for your initial blog. If you don't like Amazon or find it too overly complex you could try Digital Ocean but for the purposes of this post I won't be discussing that option here.

Setting up an Amazon EC2 Instance

Sign-up to Amazon

First let's sign-up for Amazon Web Services. Once you've signed up and confirmed your email address sign-in to your Amazon account and it should bring you to your EC2 dashboard.

Choose your EC2 instance type

Amazon EC2 instances are just barebone boxes with what's called an 'image' pre-installed on them. The image could be just the operating system such as Linux Ubuntu or Windows or another option is a full-stack install using an Application Machine Image (AMI). Now you could take the easy option here (which is what I first did) and install the Bitnami Ghost stack. You can get it from the AWS Marketplace and it'll give you a bunch of benefits like being able to use your Ghost blog right away (basically like a single-click install).

Thing there a bunch of major disadvantages to using a single-click install AMI:

  • It costs you per hour (t2.micro is $0.02/hr or just under $15/pm) plus there are EBS volume back-up charges
  • You don't know how it works under the hood - I don't know about you but that partly makes me uncomfortable especially if there are issues
  • We have less flexibility
  • We don't learn as much

If you're going to use Amazon AWS then I assume you're here to learn so I've gone through a lot of pain so you don't have to. We're going to start with a t2.micro with Ubuntu 14.04 image. Let's get started.

Spin-up an EC2 instance

On the EC2 instances tab of the EC2 dashboard select Launch Instance, select the Ubuntu Server 14.04 LTS (HVM), SSD Volume Type 64-bit (it should say it is free tier eligible). Once you've selected your Ubuntu AMI select the t2.micro instance (otherwise you'll be charged).

Click Next: Configure Instance Details, you can leave the details on the next page as they are. Select Next: Add Storage and up the size of storage to 30gb as this is the maximum your free-tier allows. Keep clicking next until you get to Configure Security Group.

Lock your instance down

Give your Security Group Name ghost-blog or something that you'll recognise and set up the following rules:

Type Protocol Port Range Source
Custom TCP Rule TCP 4567

For those of you unfamiliar with iptables or firewall rules this basically means that the EC2 instance will all traffic via the following ports:

  • 22 - This is the traditional SSH port that you use for jumping onto the box
  • 80 - Traditional http:// requests
  • 443 - Traditional secure https:// requests
  • 4567 - The port with which we'll do our continuous delivery by notifying the blog from our github account

Once you finish creating the ec2 instance don't forget to download the keypair. This will be .pem file that you use to 'ssh into' your EC2 instance -- Keep it safe!

Before you can use the .pem file you'll need to reduce it's visibility for security purposes e.g.

    chmod 400 your-key.pem

Check you can ssh to the ec2 instance by going onto the ec2 instances page on the ec2 dashboard, selecting the ec2 instance you just created from the list and copying the public DNS entry. This will be along the lines of - yours will vary depending on which availability zone your ec2 instance is in.

If any of the terms I use are unfamiliar (such as availability zone) I strongly suggest you look them up on the AWS website. For brevity, an availability zone is essentially one of Amazons data centres that back Amazon Web Services. Having multiple availability zones available ensures that your system has resilience to physical disasters such as floods, fires and terrorist attacks -- prudent.

Check you can now log into your EC2 instance:

    ssh -i your-key.pem

(Making sure you substitute the public DNS with the DNS that was assigned to your instance - this won't change unless you terminate your instance and spin it back up).

Next you can go ahead and assign your instance an Elastic IP. Technically EIPs will only be used if you have a second failover box but you need to assign alias' to Elastic IPs when resolving domain names so I suggest you do so - it's free because you will assign it to a single EC2 instance but you'll be charged if you don't use it).

To assign an elastic ip you select the Elastic IP menu selection in the left-hand panel on the EC2 dashboard. Select Allocate New Address then select the Elastic IP you created and click Associate Address and associate it to the EC2 instance you created for your blog.

Link up your domain name

So, let's recap. We've signed up to AWS and created an EC2 instance that's accessible via a public DNS address or an IP. This isn't any good for us though we need our blog to be accessible via a domain name.

Buy a domain name

If you haven't bought a domain name already get buying. Working out the name of your blog can be tricky - try and choose something that chimes with the theme of your blog and projects a certain image. Godaddy are pretty good (69p for a domain for a year), though I believe even Amazon are selling domain names now but you'll be paying more. If you buy via Amazon themselves you'll be using their name servers so you won't need this next step and things will be easier.

I'm going to assume though that like me you want to run your blog on next to nothing for a year - if so, find the best deal you can using an external domain provider and sign-up. Unfortunately, I only know how to do it from purchasing via GoDaddy not other domain hosts so you'll need to look up or ask your provider for instructions if you don't use GoDaddy (I'm in no way affiliated btw!).

Create Route 53 routing to your instance

The next step was a bit tricky I thought without any half-decent manuals to follow. Basically though we want to do the following:

  • Create a Hosted Zone for our blog
  • Copy the DNS name servers (type NS) for the hosted zone
  • Log into our GoDaddy (or other domain host)
  • Replace their name servers with the name servers for Amazon for the domain we just bought
  • Create a new Record Set in our hosted zone
  • Add the Elastic IP as the value for the type A (IPv4 address)
  • Add another Alias from to - this will mean that www (dub-dub-dub) requests will be re-routed to if people decide not to type it.

A word of caution - you may need to wait for Name Servers for Amazon to update with your domain host as this may take a bit of time. It took me a few hours for it to happen, I even noticed my domain name drop out of my registered domains list in GoDaddy - thankfully when I spoke to GoDaddy tech support (who were excellent) they told me what I did was absolutely fine and I just had to wait.

Voilá! What you should have now is an EC2 instance that is reachable via port 80 from anywhere in the world using the domain name you purchased. This perfectly places you to sort out getting Ghost onto your blog.

Remember if you enjoyed the post please sign-up to my RSS feed for an update on the next chapters. Next up we'll get Ghost up and checked in locally then we'll create all the files we need on the box so we're ready to create the Continuous Delivery aspects in the final chapter.

Feel free to message me if you have any questions and I'll be as prompt as I can be to help - thanks for staying with me and well done if you've made it this far.

Next in series: Part 2

James Murphy

Java dev by day, entrepreneur by night. James has 10+ years experience working with some of the largest UK businesses ranging from the BBC, to The Hut Group finally finding a home at Rentalcars.

Manchester, UK
comments powered by Disqus