Building a Blogging Website with Ghost

Building a  Blogging Website with Ghost

Background

While I was looking for setting up a blogging website I came across ghost. It was a interesting journey on the setup and I wanted to share the same with you.

Pre-requisite

  1. Valid Registered Domain (production only)
  2. AWS Account
  3. MAILGUN (subscribers mailing)
  4. Installing Docker and Compose in AL2023 AWS EC2

Deployment

  1. Gathering all config files

The below services are:

  • nginx-proxy - handling requests and reverse proxy for application
  • acme-companion - handling ssl certs creation and renew
  • ghost - application or blog portal/admin
  • mysql - self managed database
  • mysql-backup - for auto s3 backup every day
services:
  proxy:
    image: nginxproxy/nginx-proxy:1.6
    container_name: proxy
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - html:/usr/share/nginx/html
      - certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro

  letsencrypt:
    image: nginxproxy/acme-companion:2.4
    container_name: letsencrypt
    restart: always
    volumes_from:
      - proxy
    volumes:
      - certs:/etc/nginx/certs:rw
      - acme:/etc/acme.sh
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      DEFAULT_EMAIL: ${ADMIN_EMAIL}
    depends_on:
      - proxy

  ghost:
    image: ghost:5
    restart: always
    container_name: ghost
    environment:
      VIRTUAL_HOST: ${DOMAIN_NAME}
      LETSENCRYPT_HOST: ${DOMAIN_NAME}
      LETSENCRYPT_EMAIL: ${ADMIN_EMAIL}
      VIRTUAL_PORT: 2368
      NODE_ENV: production
      url: https://${DOMAIN_NAME}
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: ${MYSQL_ROOT_PASS}
      database__connection__database: ydvsailendar
      mail__transport: SMTP
      mail__options__service: Mailgun
      mail__options__port: 465
      mail__options__host: smtp.mailgun.org
      mail__options__secure: true
      mail__options__auth__user: ${MAILGUN_USER}
      mail__options__auth__pass: ${MAILGUN_PASS}
    volumes:
      - ghost:/var/lib/ghost/content
    depends_on:
      - db

  db:
    image: mysql:9.0
    restart: always
    container_name: db
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASS}
    volumes:
      - db:/var/lib/mysql

  backup:
    image: databack/mysql-backup:1.0.0-rc5
    restart: always
    container_name: backup
    environment:
      - DB_DUMP_TARGET=${DB_DUMP_TARGET}
      - DB_USER=root
      - DB_PASS=${MYSQL_ROOT_PASS}
      - DB_DUMP_FREQ=1440
      - DB_SERVER=db
      - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
    depends_on:
      - db
    command: dump

volumes:
  acme:
  certs:
  html:
  db:
  ghost:

compose.yaml

COMPOSE_PROJECT_NAME=blog # compose project name 
DOMAIN_NAME=************* # domain where you want to host
ADMIN_EMAIL=************* # email used for ssl by letsencrypt
MYSQL_ROOT_PASS=********* # db password used by mysql and ghost to connect
MAILGUN_USER=************ # mailgun user for the smtp
MAILGUN_PASS=************ # mailgun password for the smtp
DB_DUMP_TARGET=s3://<s3_bucket_name>/db # s3 bucket created from above
AWS_DEFAULT_REGION=****** # aws region for aws cli

.env

You can create a dir and put these 2 files in it or you can just put them under the root dir.

docker compose up -d # deploy using compose in detached mode
docker compose down compose.yaml # remove all resources created as part of the compose file
docker logs ghost # check container logs

Domain Mapping

  • Create an EIP, Attach the EIP to instance.
  • Take the EIP and create a record in Route53 for your domain.
  • Visit the domain and verify the portal and admin is available at https://${DOMAIN_NAME} and https://${DOMAIN_NAME}/ghost.
  • Enable Comment Section
    • login to admin portal
    • settings -> access
    • edit and select the commenting section to all members and save.
  • Verify the Database Backup.

Happy Reading. Please feel free to leave your feedbacks and show some love which will inspire me to write more. You can find the code in github below.

GitHub - ydvsailendar/blog-info: blog site with author details
blog site with author details. Contribute to ydvsailendar/blog-info development by creating an account on GitHub.