How to Deploy Self-Hosted Ghost on GCP Compute Engine on Free tier

There were many good options out there that require little or no technical know-how to spin up, but as a Cloud engineer, I got more pumped deploying Self-host Ghost on a GCP Compute VM. I'll be taking you through the process I followed to be able to achieve this.

Prerequisites

Create your GCP account

Google Cloud has $300 in new credits for new customers to explore Google cloud resources, and it also offers free tier usage for some products. All resources used to host our Ghost blog would be within the free-tier limit.
Create a Google Cloud account here, if you don't have one.

A domain name for hosting your blog

Register a domain name to host your blog, I registered my domain name using Cloudflare, there are other alternatives like Namecheap, Porkbun, and Google domains. I went with Cloudflare mainly because it is the cheapest when renewing in the second year.

A working DNS A-record domain should be pointed from your blog to the server's IP address

Let's get started

All resources configuration specified, are within the free tier, so there won't be any recurring expenses.

GCP project and enable Billing

Create a GCP project where you want to deploy all resources to be used by the blog and also enable billing

Spin up a VM instance on Compute engine

The next thing is to create a VM instance for ghost deployment.

  1. Enable Compute Engine API and create a new instance.

  2. Region should be us-west1, us-central1 or us-east1

  3. The machine type should be e2-micro

  4. Under Boot disk, change the image to Ubuntu, and type to standard persistent storage with a size of up to 30 GB.

  5. Allow all HTTPS traffic firewall options, to enable traffic into the instance.

  6. Leave other options as default and create the instance.

Ghost Setup on VM instance

From the official documentation, NGINX, Node.js, MYSQL, and Systemd, Ghost-CLI is packages that need to be installed on the server.

  1. SSH into the VM instance
    SSH into the instance with a Google Cloud console or with any SSH client. Create a new user
# Login via SSH
ssh root@your_server_ip

# Create a new User
add user <user>

2. Add the user to the supergroup, then log in as a new user

# Add user to supergroup to give admin rights
usermod -aG sudo <user>

# Login as the new user
su - <user>

3. Update and install new Packages

# Update package lists
sudo apt-get update

# Update installed Packages
sudo apt-get upgrade

You may be required to enter your user password.

3. Install Packages needed to run Ghost

Install Nginx
From the documentation, Ghost requires NGINX version 1.95 or higher

# Install Nginx
sudo apt-get install nginx

We then open a Firewall to allow HTTP and HTTPS connections

sudo ufw allow 'Nginx Full'

Install MySQL

# Install MySQL
sudo apt-get install mysql-server

Install Node.js

Currently, the supported version of Ghost is Node 16

# Add the NodeSource APT repository for Node 16
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash

# Install Node.js
sudo apt-get install -y nodejs

Install Ghost-CLI

According to Ghost, " Ghost-CLI is a command line tool to help you get Ghost installed and configured for use, quickly and easily. The npm module can be installed with npm or yarn."

sudo npm install ghost-cli@latest -g

4. Install Ghost

# Create directory - replace <sitename> with the name of your site
sudo mkdir -p /var/www/<sitename>

# Set directory owner - replace <user> with the name of your user
sudo chown <user>:<user> /var/www/<sitename>

# Set the correct permissions and change directory
sudo chmod 775 /var/www/<sitename>

cd /var/www/<sitename>

# Install Ghost
ghost install

5. Configure Your Ghost Blog

Ghost-CLI will ask the following questions to configure the site

  • Blog URL (Domain Blog URL linked to the server IP)

  • MYSQL hostname (use default)

  • MySQL username/password (use root/{password})

  • Ghost database name (use default)

  • Set up a ghost MYSQL user? (yes)

  • Set Up NGINX (yes)

  • Set Up SSL?

  • Enter your email

  • Set up Systemd (yes)

  • Start Ghost (yes)

If there was no error running the commands above, Congratulations. You have successfully installed Ghost, and the blog can be accessed at the blog URL specified above.

Some of the issues faced while installing Ghost
1. Low memory issues

The 1 GB server was not enough to install Ghost-CLI. I created a swap memory to add memory to the server. You can check how to do that here

2. Setting up DNS A-record domain to the server's IP address

I configured a SSL end-to-end encryption from my domain provider and on my server, you can follow the process described here.

My next post will be on how to secure our VM instance. Watch out !!!