Installing Ghost from scratch

I've done fresh installs of Ghost a few times and I thought I'd document it all here, to make it simpler for myself and others who may find this helpful. Here we go.

Includes affiliate links.

What is a "Ghost website"?

A ghost website contains the following:

  1. Domain - an address to redirect your website to.
  2. Server - a computer to host your website on.
  3. Mail functionality - a way to send emails to subscribers.

Main Setup

Buy a domain

Unintuitively, the first step is to buy a domain. You will be asked by . I like to buy mine from Cloudflare Registrar - they tend to be the cheapest ones out there.

Obtain a server

I like to just use DigitalOcean's Ghost droplet image. They have a one-click setup for Ghost, which has been very useful. However, all you really need is some space on a computer that can host a website.

If your server lives on the web, you can use any terminal or command prompt to log in to it. I like to use Tabby however to manage my servers.

Install Ghost

If you are using DigitalOcean, on your first login, the droplet will automatically start the installation.

Otherwise, you can follow their official installation guide here. On first access into the DigitalOcean droplet, all the software will get configured.

Set up MySQL for production

There is a message by DigitalOcean saying you should update your MySQL configuration. So you should do so:

  1. Get your password from the login screen
  2. Run mysql_secure_installation
  3. Follow the on-screen guide

Set up emails

Set up Mailgun

  1. Sign up for mailgun on the free trial.
  2. Follow the steps to set up your mailgun account. Enter your credit card details and select "Foundation Trial" for now.
  3. Go to account plans. Next to the "upgrade" button, click the gear button and select "Unsubscribe". You'll be on the Flex Plan, which is more relevant for us (and free too).
  4. Add your domain to mailgun by following the official guide or instructions in your account. Click "Verify DNS Settings" to make sure changes are received by Mailgun.
  5. Under receiving routes, set it to send to your support email address.
  6. Go to Sending > Domain Settings > SMTP Credentials. Click "Reset Password" and copy the value there. This will be important later for SMTP setup, which is required for verification and admin emails.

Set up on server (SMTP)

  1. Go into your Ghost folder. This is typically /var/www/ghost
  2. In config.production.json, change the mailing settings to mailgun:
  "mail": {
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "host": "smtp.mailgun.org",
      "port": 587,
      "secureConnection": false,
      "auth": {
        "user": YOUR_SMTP_USER,
        "pass": YOUR_PASSWORD
      }
    }
  },
  1. Run the command ghost restart as your ghost user.

Set up Ghost

  1. Go into Settings > Newsletters, and then add in your mailgun details following the instructions.
  2. Remember to scroll up and click "Save".
  3. Under Settings > Membership > Customise Portal > Account Page Settings, change the email you want people to reply to your newsletters to.

Monetisation

If you want to monetise your blog, there are additional steps to take.

Set up Stripe

If you want to collect payments for your website, you should have Stripe set up as well, and linked to Ghost.

Create Stripe account

Fill in your necessary details and set up payment methods.

Set up on Ghost

Go to Settings > Membership > Click "Connect with Stripe".

Set up Google Ads (or other ads)

Apply for Google Adsense

There are some criteria for that, such as having enough content on your blog, cookie consent and so on.

Add ads.txt to Ghost

This is a bit tricky:

  1. Download your theme in a zip folder (under Settings > Design > Advanced > "...")
  2. Extract all the files in the zip folder.
  3. Add a file called ads.txt with the required info into the main folder.
  4. Zip the theme back up.
  5. Upload the theme zipped folder in "Upload Theme" under Settings > Design
  6. Switch to the uploaded theme.

Security

Add swap space

To do so, follow the below tutorial.

How To Add Swap Space on Ubuntu 22.04 | DigitalOcean
One way to guard against out-of-memory errors in applications is to add some swap space to your server. In this guide, we will cover how to add a swap file t…

You can add either Osano or CookieYes, and follow their instructions from there. To add the code, you can follow this tutorial to inject code into your site:

How to use Code Injection in Ghost
Code Injection is a powerful, convenient tool to add CSS, JS, and more to your Ghost site. Learn how to get the most out of it in this tutorial.

Set up Cloudflare

It's free and can help you:

  • Protect your website from attacks
  • Keep your original server IP address safe

You can follow the instructions in "Add Zone" in cloudflare to set this up.

Set up www and non-www redirects

You can do this so that www.mysite.com leads to mysite.com automatically.

On Digital Ocean

  1. Add an 'A' record for the www. version (see tutorial)

After that, you will configure it differently based on whether you have set up cloudflare:

On server (if no cloudflare)

  1. Switch to the ghost manager: sudo -i -u ghost-mgr
  2. Use this Ghost tutorial to configure https for the secondary site
  3. Replace :
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;
    }

with:

    location / {
        return 301 https://yoursite.com$request_uri;
    }
  1. Do this for both https and non-https configurations.

In cloudflare (if using cloudflare)

Follow this tutorial to see the configurations for bulk redirects.

Redirecting www to domain apex · Cloudflare Pages docs
In this guide, you will learn how to redirect the www subdomain to your apex domain (example.com). This is a common question and can be achieved by …

Sometimes I get a too many redirects error. Check out this page to solve it:

ERR_TOO_MANY_REDIRECTS · Cloudflare SSL/TLS docs
Learn how to troubleshoot ERR_TOO_MANY_REDIRECTS when using Cloudflare SSL/TLS.

After applying bulk re-routing, I changed the encryption mode to Full, and on "Edge Certificates" I turned on everything except for Total TLS, HTTP Strict Transport Security (HSTS) and Certificate Transparency Monitoring.

Restart Ghost

Run ghost restart to check if everything is set up correctly.

Set up Github

This is to ensure you have a copy of the code running your website.

  1. Set up a repository remotely.
  2. Set up locally:
git init --initial-branch=main
git remote add origin <blog-url>
git branch --set-upstream-to=origin/main main

Set up anything else as required, such as usernames and so on.