Hosting a Ghost Blog on DigitalOcean

Hosting a Ghost Blog on DigitalOcean
Photo by Drew Tilk / Unsplash

As a first post, I thought it would be appropriate to document the process of deploying a Ghost CMS blog on a DigitalOcean droplet. I reviewed a couple of different options between the major cloud providers, and found that the most straightforward and cost-effective method was using a DigitalOcean instance.

Prerequisites

  • A basic understanding of virtualization and the Domain Name System (DNS)
  • Some familiarity with the command line of your choice
  • A DigitalOcean account
  • A purchased domain (I use namecheap, but there are many other options)
  • A CloudFlare account

Getting Started

*Disclaimer: There are other managed and more simplistic ways to set up a blog, to include Ghost's own managed service. This is a straightforward way of deploying the self-hosted version of Ghost.

image_1.7c9279ff

Create a droplet

A 'droplet' in DigitalOcean is a virtual machine. You have control over the size, security, and management of the machine. Click the green 'Create' button in the top right of the DigitalOcean landing page after logging in.

image_2.86fbbcf0

On the 'Create Droplets' page, you will first be prompted to choose an image. There are several options here, including base operating system images from Ubuntu, Debian, and CentOS.

Luckily, DigitalOcean has a premade Ghost image hosted on an Ubuntu machine. To find this image, switch from 'Distributions' to 'Marketplace' and search for Ghost. It should appear like this:

image_3.589fa242

After selecting the Ghost marketplace image, you will be prompted for a managed database cluster, which is overkill and expensive for a personal blog at this point. Ignore this dialog and continue to select the following parameters:

  • Choose a plan:
    • Shared CPU - Basic
    • CPU options - Regular with SSD
    • 1 GB / 1 CPU, 25 GB SSD Disk, 1000 GB transfer

Block Storage and Datacenter Options

Further down the page, there is an option to add block storage, which is not necessary for the purposes of this tutorial, but could be useful and offer some resiliency to your instance.

Continuing on, you will be asked to choose a datacenter region. Choose an available region closest to you in proximity, or more accurately, the one closest to your general target audience. I selected New York 1

image_4.44d13ad8

Authentication and Additional Options

Here you are prompted for the authentication scheme for your VM. I recommend using an SSH key for best security practices, but password authentication is also an option.

To create an SSH key, make sure you are using the computer that you will regularly access your VM from. Open a terminal and enter the following:

ssh-keygen -t rsa -b 4096

This command creates a new ssh key, and by default, places it in

  • Windows: C:\Users\{user}\.ssh
  • Linux: /home/{user}/.ssh

List the contents of the public key created by the ssh-keygen tool by entering:

cat c:\Users\myuser\.ssh\id_rsa.pub

# OR

cat /home/myuser/.ssh/id_rsa.pub 

The output you receive should look similar to this format:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDbwzuWnlaOkJvXO1G+UKHvihQgFekmKOiCuVcaEEJ2qK5jsE5psYxGkOhYYGyhhaf6O2YBcw0HMUp6M+pqTfXsXYvzYn89LjFg0IHF0Xt0P/OTUuKg34E8Q1zRqkQhThHqQhD2s/NXoIqec8/s1oi1oq7JKf6u8ryDEcKU/e38UqHP6g6XFCsKRGaDO2ESL3SOZf9zYc9kEMLqFPZYgFI50KnJStw+Ens00hcJTpnikAmYYzeEPrmKXNCH+r2LBAV33oYPXxp/5y7U644DeHPA9VaE2FxcxMVcijk3VTVpNVKs8yOwYDsNg7le+0Ntc1P+HUtaRc/3KeimsOSVZG0OCld6YDTl7PDn7YgljA8cJ4qyDptR1eUFkcD2lhlmR4goIVUGhDdtsTBcCg2mTxpPdjt98VI8fktkmwz4C9iAW3O90HmuXMFEWE8Ej8JJNqFBkyQ4s8I8WhYTFxsZYMC8LriIsV+lMm9AnPJ6rSv4cBsZstqfBX4jQtJOn7cZaMuKjBMm3URdklb33IySDxqQztzXWenn+UrNqiq/bvenO3qvZFHIyN4TF0pegr/JXltZ3ElahYBKx9jsfZcKQGgSuX8B1PQih6CNGCvWsB55bZMXl5O4+2KfD1oN6gVWZbpiG6qDxeSvxuI3l2eFKthbNodyWy4f8NDctmwQL1bNQQ== user@host 

Copy this output. In the DigitalOcean droplet creation page, under Authentication, select SSH keys and select New SSH Key.

The dialog that appears prompts you for the key content you just copied previously, as well as a name for the key to reference within DigitalOcean. It also provides instructions on how to create an SSH key, if necessary.

image_5.4c899570

Finalize and Create

The last section is simple:

  • Choose how many 'droplets' or VMs that you desire (in this case, 1 is fine) as well as the hostname you desire for the VM itself.
  • Add any tags that you may want to categorize or identify this workload later, but this isn't necessary and can be added later.
  • Select the DigitalOcean project you want the project to reside in. By default, the default project is assigned for you.
  • Click Create Droplet

image_6.0194aede

Setting up Ghost

Give the VM a few moments to start up, and then click on the newly-created droplet in the DigitalOcean portal. By default, the Graphs view of the VM is presented. Make note of the ipv4 address in the top left of the page, as we will need this to access the server, configure Ghost, and later, set up DNS.

image_7.c683af78

Configuring the Application

Return to your terminal and use the following command to log in to the new VM:

ssh root@<<ipv4_address>>

Upon logging in, the 'DigitalOcean 1-Click Ghost Installation' tool will run automatically.

After the initial setup, the screen will present some basic information, such as the output from the npm install command ran in the tool, as well as initial domain information. At this point, you will need to point your domain to this public IP address on your DNS provider. In my case, I am using the Cloudflare free tier to proxy my web traffic to my DigitalOcean droplet.

image_8.6067d34b

Press enter when prompted, and Ghost will continue to install.

image_9.47d8db98

The first prompt will ask for a blog URL. Here, enter your registered domain name. In my case, https://www.datalinkready.com

By using https, the next prompt will ask for an email address to register with the SSL certificate

image_10.85207b67

Once Ghost completes its installation, it will present you with the link to the administration panel of your new Ghost site. By default, it will take the format of

https://<yourdomain.com>/ghost/

If DNS was set beforehand, you should be greeted with the following when traversing to the admin page:

image_11.25e6863a

It is important to create the admin account immediately after installing Ghost, as anyone can traverse to this page and take ownership of the site before the initial account is made.

Finishing Up

After creating the admin user, your Ghost site should be ready to go and open to the public. Log in to the admin panel to view web statistics, post scheduling/writing options, theme options, subscriber options, and more.

Ghost makes it pretty easy to get up and going with some sleek designs within their template library.

image_12.776088b7

The settings cog at the bottom left of the page opens the settings menu, where the majority of Ghost options reside.

Within the design section, you can select Change Theme in the bottom left corner. This renders a page of sample templates to choose from, or the ability to upload your own.

image_13.fa9faa16

Ending Thoughts

Hopefully this tutorial enables you to start the blog you were thinking not to, or helps inspire a project for a portfolio, or to just learn something new. I will be writing up a tutorial on how to set up Cloudflare DNS in the near future, for those that want to use that for their Ghost deployment.