How to Self-Host a Ghost Blog

Self-Hosting Jul 14, 2021

Last Updated: 20th July 2021

What is Ghost?

"Ghost was founded in April 2013, after a very successful Kickstarter campaign to create a new platform focused solely on professional publishing. Our mission is to create the best open source tools for independent journalists and writers across the world, and have a real impact on the future of online media.

Today Ghost powers an incredible range of websites; from individual bloggers who are just getting started, to large teams of writers and editors at some of the largest organisations in the world. We've built a sustainable business around a free core application, funded by a premium platform as a service to run it on." - ghost.org/about

Ghost Pro vs Self-Hosting

Feature Ghost Pro Self-Hosted
Auto-Updates
CDN
DDoS Protection
Backups
Have fun tinkering
Full Customisation
Stress-Free
Funds Ghost Development
Cost $9+ pm VPS($2-10)

Ghost Pro (Not affiliated)

Self-Hosting?
Free 4 months Hetzner VPS (€20 Credit) - https://s.cyberhost.uk/hetzner (Referral)

Prerequisites

  1. Setup your server
  2. Install Docker & docker-compose

Install

  1. Create docker network:
    sudo docker network create --driver=bridge --subnet=10.10.10.0/24 --gateway=10.10.10.1 dockernet

  2. Create a ghost folder in your home directory:

cd
mkdir ghost
cd ghost
  1. Use the following docker-compose template:
    nano docker-compose.yaml
version: '3.1'

services:

  ghost:
    image: ghost:alpine
    container_name: ghost
    restart: unless-stopped
    environment:
      # see https://docs.ghost.org/docs/config#section-running-ghost-with-config-env-variables
      database__client: mysql
      database__connection__host: 10.10.10.2
      database__connection__user: root
      database__connection__password: <PASSWORD>
      database__connection__database: ghost
      url: https://<SITE-URL>
    volumes:
      - ghost:/var/lib/ghost/content
    networks:
      default:
        ipv4_address: 10.10.10.3

  ghost-db:
    container_name: ghost-db
    image: mysql:5.7
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: <PASSWORD>
      MYSQL_DATABASE: ghost
    volumes:
      - ghost-db:/var/lib/mysql
    networks:
      default:
        ipv4_address: 10.10.10.2

volumes:
  ghost:
     driver_opts:
           type: none
           device: <PATH1>
           o: bind
  ghost-db:
     driver_opts:
           type: none
           device: <PATH2>
           o: bind
networks:
  default:
    external:
      name: dockernet
  1. Spin it up: sudo docker-compose up -d

Setup Reverse Proxy

  1. Install Caddy: cyberhost.uk/caddy-setup/
  2. Create Caddyfile
cd
nano Caddyfile
  1. Add the following template:
example.com {
  encode zstd gzip
  reverse_proxy 10.10.10.3:2368
  header {
    X-Content-Type-Options nosniff
    Referrer-Policy  strict-origin-when-cross-origin
    Strict-Transport-Security "max-age=63072000;"
    Permissions-Policy "interest-cohort=()"
    X-Frame-Options SAMEORIGIN
    X-XSS-Protection 1
    -x-powered-by
    -via
    -server
  }
}
  1. Reload the caddy config: caddy reload

  2. Head to your Ghost Blog!

  3. Create your admin account by visiting /ghost https://example.com/ghost

Ghost Welcome Page

Next Steps:

How to Secure and Optimise your Website or Blog
Last Updated: 10th July 2021 Intro It’s important to optimise your website as this will reduce loading times, and stop viewers from abandoning your page. Search engines also factor in loading times, so it’s a win win to optimise your website, happy viewers, high rankings. I’ve spent many hours opt…
Adding Varnish cache server to Ghost Blog - Docker
The new setup includes a Varnish server which has been deployed using docker. This is positioned between Caddy (Reverse Proxy) and Ghost...

Comments

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.