May 18, 2018

Self-hosting Ghost

Previously I was using Ghost (Pro) to host my blog, however, the tiny amount of traffic did not justify the annual cost. I decided to move the site over to my own host and use Cloudflare as a CDN to provide caching. I also setup SNI Proxy to allow for multiple sites on the same external IP, athough this is not an officially supported configuration.


  • Ubuntu 16.04
  • SQL database (local or remote)
  • Domain name, with nameservers pointing to ->
  • Cloudflare DNS resolvers, which point to ->
  • Static IP or Dynamic IP if a DNS updater is used

Installing Ghost

Add Node repo

curl -sL | sudo -E bash

Install nginx, node, build tools

sudo apt install -y nodejs nginx build-essential

Install ghost

sudo npm i -g [email protected]

Create SQL database

I chose to do this on my remote SQL server, but this could be a locally installed SQL/MariaDB instance.


If you need a local database:
sudo apt install mariadb-server
Then follow the same steps, substituting localhost for the hostname.

For remote SQL server

Login as the root user (will prompt for password):
mysql -u root -p

CREATE USER 'username'@'ghosthostname';
CREATE DATABASE ghostdatabase;
GRANT ALL PRIVILEGES ON ghostdatabase.* TO 'username'@'ghosthostname' IDENTIFIED BY 'password';

Exit the SQL session with \q

Test SQL connection

Requires a sql client installed
sudo apt install mariadb-client
mysql -u username -h databaseservername -p
You should be prompted to enter the password, and not get a failed connection message.

Back to the ghost install

Create the ghost install directory:

sudo mkdir -p /var/www/ghost

Change the directory owner:

sudo chown -R USERNAME /var/www/ghost
NOTE: it is best to own/run as a user created specifically for ghost

Switch to the directory:

cd /var/www/ghost

Install ghost:

ghost install

Fill in the details for your site URL and SQL database when prompted. The wizard will mostly take care of the rest, but check the below for gotchas.

Things to note


If you intend on hosting your site over HTTPS, enter the site name with https://YOURDOMAIN otherwise ghost will have issues later (broken redirects).

SSL certificates

Ghost will automatically use Let's Encrypt to setup and configure nginx for serving your site securely over HTTPS. However as there are several sites behind my single external IP, answer No to the SSL setup question. I set this up later and it's covered in the Cloudflare/Let's Encrypt article.

Reconfiguring Ghost

If later you need to adjust what you entered during ghost setup, you can modify the configuration.
cd /var/www/ghost
ghost setup STEP
where STEP is the stage that broke

If something totally breaks

cd /var/www/ghost
ghost uninstall

The nuclear option

If ghost uninstall doesn't fix it, something went really wrong.
sudo rm -R /var/www/ghost

Allow nginx through the firewall

If UFW is enabled, we need to let nginx through:
`sudo ufw allow 'Nginx Full'


Test your site by visiting https://HOSTNAME

Updating Ghost

To update the Ghost command line interface

sudo npm install -g [email protected]

To update the installed Ghost blog

cd /var/www/ghost
ghost update

We're Done!

It's never done...