Create a free JAMStack blog using Ghost, Heroku and Netlify

Zing Zai
7 min readFeb 22, 2020
Ghost

Background

Blogging is a great way voice your thoughts, share your adventures and spread your ideas. It allows people to connect with one another.

Today, there are many blogging platforms out there such as WordPress.org, WordPress.com, Wix, Ghost and even Medium (the platform I’m writing on…). Although there are many great options, I want to create a blog that will fit most bloggers’ use-case.

Use Case

  1. Free; blog must remain free/low-cost.
  2. 100% availability; blog must always be up.
  3. Zero maintenance; blog must easy to maintain.
  4. Custom Design; blog must be unique and personalised.
  5. Custom Domain name; blog name must be easy to remember.
  6. Multiple contributors; different users can contribute to the blog.
  7. Friendly User Interface; writers must find interface easy to write on.

Why and what is Ghost, Heroku and Netlify?

Ghost

After evaluating the platforms, Ghost and Wordpress.org were the 2 platforms remaining… Most platforms required some sort of payment while others did not allow a custom domain name. At the end of the day, I chose Ghost for its friendly UI.

Ghost: an open-source headless Content-Management System(CMS).

Heroku

You can use the cloud-hosted Ghost… but you have to pay for it. I look for free alternatives and rather host the servers and data myself…

Heroku: A platform as a service (PaaS) that will enable you to run and operate your Ghost server.

Netlify

To achieve 100% availability and zero maintenance, I want to deploy the blog as a static website. This would allow the blog to be independent from the Heroku servers.

Netlify: An all-in-one platform for automating modern web projects.

Prerequisites

  1. Heroku Account
    Create a Heroku Account, here.
  2. GitHub Account
    Create a GitHub Account, here.
  3. Netlify Account
    Create a Netlify Account, here. Connect your GitHub account to access your repositories.
  4. Custom Domain Name
    If you are a student, here is how you can get free custom domain names!
    Sign up for
    GitHub Education. You can get free custom domain names from name.com, namecheap, .TECH domain.

Step 1: Deploy Ghost 3.X server on Heroku

To start off, use one-click to deploy a Ghost server on your Heroku. By hosting your own Ghost server, it gives you full control over your blog.

Free dyno and add-ons
  1. You may be prompted for payment info. Do not worry, everything is $0.00!
    Hint: Despite being free, you might want to try using a dummy credit card
Ghost server on Heroku

2. Next, enter a App name, choose a region and deploy the app.

This project automatically install add-ons and create accounts for:

MySQL Database and Tables
Mailgun Email Service
  • Cloudinary : To store images and video resources;
    You can replace Cloudinary with S3. I will not cover the details.
  • JawsDB MySQL: To store actions, emails, integrations, members, permissions, posts, posts meta, roles, tags, settings, users etc.
    From Heroku app overview page, click on the JawsDB add-on you installed to access your JawsDB database dashboard. You can use the credentials and MySQL Workbench to connect to your JawsDB to access your data.
  • Mailgun: To send, receive and integrate emails.
    Your blog collaborators must be authorised receipents and agree to receive emails before they will receive emails from Mailgun. More info, here
Ghost Admin

3. After Ghost have been deployed, visit Ghost Admin at https://YOURAPPNAME.herokuapp.com/ghost and set up your admin account

4. Next, try to access your blog at https://YOURAPPNAME.herokuapp.com.

Step 2: Deploy a starter frontend on Netlify

Although you can already access your blog in Step 1.4, it is still heavily dependent on the Heroku server. If your Heroku server fails for any particular reason, your blog will go down…

Introducing JAMstack!

JAMSTACK

To ensure better resilience for your blog, you can deploy a static site with Netlify and use Ghost as a headless CMS. This leverages on the modern JAMstack that decouples the frontend and the content.

More details on why we want to use JAMstack to build websites.

Gatsby Starter Ghost starter project

GitHub project from TryGhost/gatsby-starter-ghost

Fork this GitHub project from TryGhost. It is a frontend starter template to build lightning fast websites with Ghost and Gatsby. For other theme templates, from JAMStack Themes.

Netlify: Next, login to Netlify, choose and link the GitHub forked repository to Netlify. After linking, any changes to the GitHub repository will trigger a build and deploy the site on Netlify.
Note: If you are using the starter template, use the default build settings on Netlify

Netlify Overview — Successful deployed website

Upon completion of the first build, visit the blog by clicking on the custom domain name provided by Netlify and you’ll be able to see a similar
i.e. https://hungry-fermat-bc2e0c.netlify.com

Step 3: Integrate Ghost to Gatsby & Netlify

From the Ghost Admin panel, create 2 custom integrations — Gatsby & Netlify.

3.1 Gatsby: Populate content from own Ghost server

Gatsby Integration

Ghost Admin: To configure our frontend Gatsby project to populate contents from Heroku Ghost’s server, we create a Gatsby integration. Copy the values for these keys:
1. Content API Key
2. API URL

Gatsby project: Open .ghost.json and change contentApiKey and apiUrl respectively with the values above.

3.2 Netlify: Updates in Ghost will trigger Netlify frontend re-builds

Netlify’s Ghost build hook

Netlify project: Create a new build hook and copy the webhook URL.
Under Site settings > Build & deploy.

Netlify Integration Webhook

Ghost Admin: Create a new integration webhook.

Now, whenever there is a change to Ghost (new design, new post, edit to existing post, delete of post), a webhook will be sent to Netlify to trigger a new build on your static site.

To test whether things are running correctly, create a post from Ghost Admin. Upon creation, verify:
1. Ghost triggered a new Netlify build and deployment of your static site.
2. Site populated the contents from your Ghost server.

Step 4: Change to custom Domain Name

Most readers wouldn’t want to enter a Netlify link to access your blog.
Let’s change it to a custom domain name with secured encryption by leveraging on Netlify DNS.

Netlify DNS

Netlify: Under Netlify Domains, you can register a new domain name or add a domain you owned.

If you want to register a new domain name through Netlify;
No action required. Netlify-registered domains are automatically configured to use Netlify DNS.

If you already have a domain name with another provider;
DNS Provider
: Next, login to your domain provider and change your nameservers. This step takes advantage of Netlify’s managed DNS service by deletgating the domain you registered with another provider.

Register your domain

Netlify project: After you have Netlify DNS set up, add the domain alias to your Netlify site. Now whenever a reader hits your domain name, it will automatically be routed to your blog!

Next, secure your site by clicking on Secure Site under the HTTPS section.
(last section under Domain Management)

Heroku: To wrap things up for custom domain name, under Settings Config Var, configure APP_PUBLIC_URL to your custom domain. Ghost will use this URL for Search Engine Optimisation (SEO).

Step 5 : Integrate other webhooks (Optional)

Google Analytics: Track site visits to gain deeper understanding of your readers

I faced some issues when followed the official guide. This was what I did to overcome it;

After setting up a new Google Analytics property, a tracking ID will be given.

gatsby-config.js file

Gatsby project: Run npm install gatsby-plugin-google-analytics , go to .gatsby-config.js and include the JSONObject with tracking ID as seen above.

Conclusion

JAMstack is revolutionising the way websites are being built. In this step-by-step tutorial, I demonstrated how you can create free, customisable and static that will always be available to your readers.

Acknowledgements

SNathJr: https://github.com/SNathJr/ghost-on-heroku

TryGhost: https://github.com/TryGhost/gatsby-starter-ghost

--

--