Setting up a Self-Hosted Ghost Blog on AWS EC2

Setting up a Self-Hosted Ghost Blog on AWS EC2
Credit: Šimom Caban / Unsplash

So you want to host a Ghost site on an Amazon Web Services EC2 server, eh? Luckily, it's not that complicated thanks to a nifty image from Bitnami.  

Disclaimer: this is how I did it, I'm not a professional web host, results may vary. If something doesn't work, go back and make sure you did everything correctly.

Section 1. Setting up the URL and DNS

Step 1. Acquire a domain name from your preferred domain registrar. I used Google Domains. Find the area for DNS settings. Keep this page open as you will need it in a moment.

Step 2. Head to the AWS console, and if you don't have an account already, do that. From the AWS console, go to the Route 53 Dashboard using the search bar. You're going to create a hosted zone in Route 53 which will route your domain to your website.

Remember to add your own info

Fill in your website's information here and make sure to create a Public hosted zone so that the outside world can access your site.

Then you'll see the Hosted Zone back in the dashboard. Select it to open up your records panel. You will see two records: an NS record with four lines, and an SOA record which you can ignore.

Here's where you will need to go back and edit the information on your domain registrar's DNS settings page.

Under the DNS settings, you will need to make sure that you are using "custom name servers" for your domain. It should then look something like this:

Google Domains version of a DNS settings page

Copy over the four lines from the NS record back in AWS Route 53. They should looks something like:

ns-854.awsdns-27.net.
ns-1938.awsdns-59.co.uk.
ns-1668.awsdns-34.org.
ns-418.awsdns-21.com.

Once you've copied the NS records from Route 53 to your domain's DNS settings, make sure that your "TTL" setting is set to 60 seconds so that you won't have to wait for the DNS to update. Save your DNS and return to AWS. (Leave route 53 open as you'll need it again. You can close your domain registrar now.)

Section 2. Setting up the EC2 instance and AMI

That's fancy talk for "setup your server with a preconfigured Ghost installation from Bitnami."

Go to the AWS marketplace from the search bar. Search for "Ghost packaged by Bitnami". Go to the details of the AMI. Click on "Launch new instance."

Probably the least helpful screenshot so far

Leave everything on the next page as it is, unless you want to launch your site in a Region other than Us-East-1 (if you don't know what that means, you can move on). Then click "Continue to launch from EC2."

Name your server after your site. 

Scroll down to the section that says "Instance Type." Select the instance type you want. If you are just starting out, I'd recommend "t2.micro" as it's cheap and does the trick while still being eligible for the free tier. If you need to upgrade later you can easily do so in EC2, part of the beauty of the platform.

Next, create a Key Pair in EC2. If you don't know what an SSH key pair is, don't worry about it, just follow along. Name your Key Pair after the site, and select PPK. (Unless you want to use OpenSSH instead of PuTTy, in which case you can leave it as a .pem file. You know who you are...)

Click on "Create Key Pair" and save the resulting download somewhere you'll be able to find it. You'll need it again in a bit.

You can leave everything under "Network settings" and "Configure storage" as they are by default.

When you've completed all the steps above, click on Launch instance to create your server and blog all at once.

I like to count it down from 10... 9... 8...

Now you've created an EC2 instance and web server with a preinstalled Ghost blog. Pat yourself on the back, but don't pop the champagne yet, there's still a few important steps to complete.

Section 3. Accessing your default Ghost site and routing your DNS

Step 1. Getting your public IPv4 address and default login credentials

So now the server exists, and after a few minutes, you can visit the default blog page. How? First, navigate to the EC2 dashboard in AWS if you weren't automatically redirected there. If you selected a region other than US-East-1, make sure to select your region from the top menu.

Then click to see your "Instances Running" page, or select "Instances" from the left sidebar. You should see your new server with a green checkmark on it.

Click on the instance ID to open the info panel. Are you ready to see your site in action? Copy and paste the Public IPv4 address of your instance (it should look something like "ec2-xyz-us-east-1.compute.amazonaws.com") into your browser bar to see your default Ghost blog.  You'll probably get a browser security warning. Just power through it.

Now that you're blog is alive, it's time to get the default login credentials.

Click the checkbox to the left of your instance back in the EC2 dashboard. Then select Actions > Monitor and Troubleshoot > Get System Log.

You will see a bunch of code that looks like a terminal. Scroll until you find the box made out of pound symbols. Inside will contain your default credentials.

Copy that password and username and save it somewhere, preferably a secure spreadsheet or doc in the cloud. You'll need it for multiple logins.

Now you can go back to your site and add /ghost to the URL to login to the backend. Before you do that, though, you might want to complete the next step of routing your domain name to the site.

It's finally time to return to the Route 53 console. You did leave that tab open, right?

Step 2. Routing Your DNS with Route 53

Somewhere along Route 66..
Close enough. Credit: Morten Andreassen / Unsplash

In the Route 53 hosted zone where you found your NS records, it's time to create a couple of new records.

First, create an "A" record and leave the "subdomain" box blank. Then, paste in your Public IPv4 Address from your EC2 instance into the Value box.

TTL should be set to 60 if you don't want to wait. Make sure to use the PUBLIC IPv4 address or this step won't work. 

Then, create a CNAME record, this time filling in the subdomain box with "www", and putting your domain without the "www" into the Value box. This step is technically optional but important if you want the "www" version of your domain routed to the "non-www" version.

After a minute, the DNS should route the domain you setup earlier to your new Ghost blog.

Now you can safely go to yourblog.com/ghost and enter the default username and password to start configuring your ghost site. There's only one very important step left! (Even if you don't think you need HTTPs, the next section contains the instructions for connecting to your server via SSH and accessing the Ghost-cli, which is useful for many reasons, so I suggest you continue reading.)

Section 4. Server Admin & SSL/HTTPs

If you don't setup HTTPs, users who try to visit your site might get a security warning because you won't have a secure connection. It also means you might be susceptible to man-in-the-middle attacks, so make sure to do this step if you have any intention of using this site for anything remotely important.

Luckily, Bitnami has also made this easy.

Step 1. Accessing your site via SSH/PuTTy

If you haven't already downloaded and installed PuTTy, head to PuTTy.org

After you install PuTTy, open it up and paste your Public IPv4 address into the "hostname" box.

Then, its time to remember where you stored that .ppk file from Section 2. Under the left-side menu, select connection > SSH > Auth. Then click the browse button to select your SSH key. This is a file that acts as a password for your connection to the server.

Once connected, you can faithfully follow the instructions here to create an SSL certificate and enable HTTPS for your site. Wow!

That was quite the journey! It's not too difficult and could even be a good starter project for using AWS EC2 images.