Host a Ghost Blog on Google Cloud Platform for Free
There are so many ways to get started with a personal blog or website these days. For the majority of users, subscribing to a website-as-a-service provider such as Wix, Squarespace, or the hosted versions of Wordpress or Ghost is an easy and hassle-free way to get started. Others like myself who like to tinker, may instead be interested in serverless options like Github Pages or running their own webserver on a cloud provider such as Digital Ocean, Amazon Web Services (AWS), or Google Cloud Platform (GCP).
This post documents my personal experience setting up a self-hosted Ghost blog on GCP. At the time of writing Google Cloud offers a free trial that includes $300 USD or local equivalent of credit, which is intended to help you get your feet wet with the platform. In addition to the credit, they also offer a very generous Free Tier which is perfect for hosting a small blog or website.
Let's get started.
Register a domain
Before you do anything else, you'll need to register a domain name if you haven't done so already. I personally use and highly recommend Google Domains. However, feel free to use any domain registrar you like. Hover and Name.com are also great options I have used in the past and can recommend.
Set up your free GCP Account
- Head over to https://cloud.google.com/free/ to review the offerings and when you're ready, click "Get started for free" to begin.
- If you're not already signed in, you'll be prompted to sign-in to your Gmail account. Agree to the GCP terms and conditions and then continue on to fill in our account and billing details.
- Select the account type according to your needs, fill out the required account & billing information, and finally click "Start my free trial" to complete account creation, after which you'll be redirected to the GCP Console.
Set up an Ubuntu VM Instance
(optional) By default GCP creates a project for you named "My First Project". Create a new project or rename the default project to fit your own organizational needs.
- To rename the default project, click "Go to project settings" on the Project Info Card found in the Project Dashboard. On the following screen update the Project Name and click save.
- To create a new project, from the top navbar click the down arrow next to the current projects name and select "New Proejct". On the next screen, fill in your project name, click "Create". Once the new project has been successfully created, you'll receive a convient notification which you can click through to the new projects Dashboard.
Enable Compute Engine for your project, then click Create Instance and configure a new VM instance with the following settings based on the Free Tier usage limits. Leave the other settings alone unless you know what they do:
- Name: you only have one chance, so name your instance something memorable
- Region:
us-west1
,us-central1
,us-east1
- Zone: any for the region you've chosen
- Machine Type:
e2-micro
- Boot Disk
- Operating System: Ubuntu 20.04 LTS or 22.04 LTS (x86/64)
- Disk Type: Standard Persistent Disk
- Disk Size: 30GB
- Firewall: check to enable both
Allow HTTP
andAllow HTTPS
--- by doing this your firewall configuration will be managed via GCP.
Now that our instance is up and running, it's time to install and configure Ghost and the necessary software to run it. For the most part we'll be following the official guide to installing Ghost on Ubuntu, but we'll be making some changes for use with GCP.
Configure the server
Login to your new instance via the Google Cloud Console by clicking SSH in the row of the instance you want to login to. Once you've logged in, you'll notice that Google Cloud has already set up a non-root superuser for you, nice!
Update Ubuntu
Since this is a fresh install, we should first check for and install any updates available with the following commands.
# Update package lists
sudo apt-get update
# Update installed packages
sudo apt-get upgrade
Install NGINX
Run the following command to install NGINX. Since GCP is handling our firewall configuration, we can skip the step to configure ufw
documented in the official instructions.
# Install NGINX and MySQL
sudo apt-get install nginx
After installation has finished, confirm that NGINX is running by copying your external IP address from the row that corresponds with your instance in the GCP dashboard, and enter it into a new browser window in the following format (note that it should be HTTP, not HTTPS)
http://your_ip_address
If you're greeted with the default "Welcome to Nginx" splash page, then Nginx has been successfully installed.
Now that we've confirmed NGINX is installed and working, we should disable the default site.
# Navigate to the Nginx enabled sites directory
cd /etc/nginx/sites-enabled
# Remove default site
sudo rm default
# Restart Nginx
sudo systemctl restart nginx
Install and configure MySQL
Run the following commands to install and start MySQL.
# Install MySQL
sudo apt-get install mysql-server
Next we'll need to secure MySQL by running the mysql_secure_installation
script which will walk through a series of prompts to secure the installation. As part of this process, we'll be asked to set a password for the root MySQL user. However, on Ubuntu the root MySQL user is not configured to authenticate with a password, which at the time of writing will cause an error to occur preventing us from completing the script. Before we run the script, we'll need to complete the following steps to manually set a root password. If you're interested to learn more about this problem, Digital Ocean has a handy write up that goes into more detail.
Open the MySQL shell.
# Enter MySQL Shell
sudo mysql
Run the following ALTER USER
command to change the root user's authentication method and set a password.
# Set a root password and temporarily change the authentication method
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
# Exit MySQL shell
exit
Next, run the mysql_secure_installation
script and follow the prompts.
# Run mysql_secure_installation
sudo mysql_secure_installation
If this is your first time running the script, you'll first be asked whether you want to install the Validate Password Plugin which will provide feedback on the strength of your password.
Next you'll be asked whether you want to change the root password. Select N
here since we'll be reseting the authentication method later. Finally select Y
for the following prompts to secure the installation and complete the script.
After securing the installation, open the MySQL shell again and reset the root MySQL user's authentication method back to the default setting.
# Open the MySQL prompt as the root using the password we set earlier
sudo mysql -u root -p
# Reset the authentication method back to auth_socket
ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
# Exit MySQL shell
exit
Install Node.js
At the time of writing, Ghost requires either Node v14 or v16, with the latter being recommended. I had issues installing Ghost using v16 --- the installation would process would hang --- and instead switched to v14 which worked without any issues.
# Make sure we're in our Home Directory
cd ~
# Add the NodeSource APT repository for Node 14
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash
# Install Node.js
sudo apt-get install -y nodejs
Install Ghost-CLI
Now that we have Node installed, we can use npm
to install the Ghost-CLI which will help us install and configure Ghost.
sudo npm install ghost-cli@latest -g
Install and configure Ghost
Now that we have the necessary software packages installed, we can proceed with installing and configuring Ghost. For this process, we're can simply follow the official instructions. Be sure to replace your_site_name
and your_user_name
with your own values.
Note: Your username can be found in the console to the left of the prompt in the following format: your_user_name@your_instance
# Create an installation directory with correct user and permissions
cd ~
sudo mkdir -p /var/www/your_site_name
sudo chown your_user_name:your_user_name /var/www/your_site_name
sudo chmod 775 /var/www/your_site_name
Finally run the ghost install
command.
# Navigate into your installation direcctory
cd /var/www/your_site_name
# Install Ghost
ghost install
The installation process can take awhile, so sit back and relax. After the files have been downloaded, the installation process will kick off a series of questions to help you configure your site:
- Blog URL: enter
your_domain_name
including either HTTP or HTTPS - MySQL Host Name: press enter to accept
localhost
unless you have a different setup - MySQL User / Pass: enter
root
and the associated password --- this will be used to create the new database and setup a specific user for the database - Ghost database name: press enter and let Ghost set this up
- Set up a ghost MySQL user: yes
- Set up Nginx: press enter to accept and let Ghost handle this. you can customize the configuration later if you need to
- Set up SSL: If you entered an HTTPS domain name earlier, then you can let Ghost setup SSL for you using acme.sh (LetsEncrypt)
- Set up systemd: yes
- Start Ghost: yes
If you ran into any issues during this process, you can always rerun ghost setup
to reconfigure the installation. If you disabled password authentication for the root MySQL user earlier, you probably ran into an issue setting up the Ghost MySQL user. Refer back to the MySQL installation step to re-enable password authentication and then rerun ghost setup
to reconfigure your site.
That's it! You've successfully installed Ghost on Google Cloud Platform. Now just point your browser to yourdomain.com/ghost
to create a user and start writing!