Self Hosted Blog with Ghost

Self Hosted Blog with Ghost

Ghost is a powerful, scalable, self-host-able platform that allows you to share your content while retaining 100% control.

I am making this pseudo-guide because, when I was setting up Ghost for the first time myself, I found a lot of detailed guides but none provided clear and simple steps for exactly what I was looking to do. That being said, this is just a simple guide on how I got Ghost working for me, and there are probably better ways to do all of this.


PREREQUISITES:

  • Own a custom domain
  • Have Docker and Docker Compose installed
  • Reverse Proxy (Caddy)

SMTP2GO

Free email sending

This part is not necessary for general blog posting but is required if you want people to be able to sign up for email updates when you make a new post. The actual email updates that get sent out will be handled by Mailgun later in this guide.

SMTP2GO is a simple service that allows you to connect a domain and generate SMTP credentials to allow programs and devices to send emails from that domain. It is free if you send less than 1,000 total emails per month from connected domains, so is perfect for our use case.

  1. Sign up at https://www.smtp2go.com/pricing/ (you will need to use an email address with a domain you own, so not gmail/yahoo/etc.).
  2. Add "Verified Sender" by entering your custom domain you would like the emails to come from.
  1. Update DNS for your domain. Use "Set up automatically" to pull up a sign in prompt to log into your domain registrar to let SMTP2GO to update the needed DNS entries on your behalf. You can also select "Set up manually" to get the needed DNS entries to update your DNS yourself.

4, After some time, select "Verify" and wait for the domain to go from "Unverified" to "Verified".

  1. Now that you have a verified domain, you can create an SMTP user. Navigate to Sending>SMTP Users>"Add SMTP user".
  1. Set a username (note: this will only be used to authenticate the SMTP user and not related to the sending address). A password will also be auto generated for you.

Now you have an SMTP account to use for the Docker Compose file in our next step.

Docker Compose File

Create a file named compose.yml and open it with a text editor. Inside of it place the following while making the following updates.

Update password1 to a unique password, making sure it matches in the "db" section

Update blog.yourdomain.com to be the full URL you will want your blog accessible from

Update smtp2goUser to be the username you created in SMTP2GO

Update smtp2goPass to be the password that was set for the username in SMTP2GO

Update email@yourdomain.com to be the address you will like emails to come from

services:

  usagiroxy-ghost:
    image: ghost:6-alpine
    restart: always
    ports:
      - 8085:2368
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: password1
      database__connection__database: ghost
      url: https://blog.yourdomain.com
      mail__transport: SMTP
      mail__options__host: mail.smtp2go.com
      mail__options__port: 587
      mail__options__auth__user: smtp2goUser
      mail__options__auth__pass: smtp2goPass
      mail__from: email@yourdomain.com
      
    volumes:
      - ghost-data:/var/lib/ghost/content

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password1
    volumes:
      - ghost-db:/var/lib/mysql

volumes:
  ghost:
  db:

I would recommend creating a folder named ghost and placing the compose.yml file in it with two new folders named ghost-data and ghost-db.

Then navigate to the folder containing the compose.yml file and run "docker compose up" to create and start the container.

DNS

For this part I will assume you are using Caddy simply because that is what I am using but the general idea should be the same for any other tool.

Update your Caddy file to have the URL you set in the compose.yml file to redirect to the correct port that was also set in the file.

blog.yourdomain.com { # Ghost on VPS
	reverse_proxy localhost:8085
}

You will also want to make sure that your domain name is pointing to the server hosting Caddy and the Ghost app. This configuration is outside the scope of this guide but I plan on making another guide on Caddy soon that should help if you have questions on this bit.

Mailgun

The last bit of technical set up is getting Mailgun configured. Mailgun is an email delivery service that is designed for sending out emails to many recipients at once. Currently it is the only service officially supported for sending out newsletters in Ghost.

First, make sure you have a Mailgun account set up. If you do not have one yet you can make one for free at https://signup.mailgun.com/new/signup (you can uncheck the credit card option).

  1. In Mailgun, select "Send" on the left, then "Domains" , and "Add new domain".
  1. Fill out the info using your custom domain. It is recommending to use a subdomain so add mg. in front of your domain.

3, Now you need to update your registrar DNS similar to how you did for SMTP2GO earlier. Like with SMTP2GO you can select the automated option or enter the DNS info manually.

Now we have Mailgun set up and can implement it in Ghost.

I recommend you complete the following steps in a new tab in your browser, leaving Mailgun logged in so you don't need to bother entering your account credentials again.

  1. Open up your Ghost admin portal by navigating to the URL from your compose file but add /ghost at the end. Select "Settings" in the bottom left.
  1. Select "Newsletters" on the left, make sure Newsletters are toggled on, then click on "edit" in the Mailgun section.
  1. Click on the Mailgun Dashboard link to take you to directly to the needed spot to get your API key and info.
  1. Click "Create key" in the top right and give it a description (ex. Ghost Blog).
  1. Copy the generated key to your clipboard and save it somewhere safe, you will not be able to view it again. Then click Done.
  1. Back in Ghost, set the Mailgun region and Mailgun domain to match what you set when setting up your domain in Mailgun, then hit Save.

Now you are all set. You can start customizing Ghost from your admin portal to make it how you like and start making posts.