/ Raspberry Pi

Blogging with a Slice of Raspberry Pi


Your hosting renewal is coming up. You are not that happy with forking out the hard earned dollars. Its a Saturday night, plans have been cancelled. You are bored and there is some cold beer in the fridge. You have a spare Raspberry Pi, a fibre connection, a static IP, and a penchant for tinkering. Hmmm...


And so the decision to self-host came about :) Honestly, I made some mistakes and ended up rebuilding the solution three times! I learned much about configuring Linux, Nginx and the Ghost platform - and just how powerful and versatile the Raspberry Pi is!
I thought I would document the journey for you (and as a reminder for me :D). Next things to look at are high availability and backup.

The Components

  • Raspberry Pi 2 with a 16GB card running debian stretch lite.
  • Uncomplicated Firewall, adds a layer of security and comfort.
  • Nginx, free, open-source, high-performance HTTP server and reverse proxy.
  • MariaDB, popular database server.
  • Ghost, lightweight and simple blogging platform.


First some assumptions,

  • I will assume you have prepared your SD card and have SSH access to your Pi. I'll do a quick tutorial on this if interested :D
  • I am assuming you know how to update your DNS and have a static IP and have port forwarding configured on your router.
    These steps are pretty straight forward. I'll try to post some details on these if there is interest.
    Ok, ensure you are using the latest packages and are up to date.
sudo apt-get update && sudo apt-get dist-upgrade -y

Configure the Firewall

Allow SSH from your workstation (adjust to suit).
Allow 'Nginx Full', which allows HTTP and HTTPS traffic.
Finally, enable the firewall - Check that IP address :D

sudo ufw allow from to any port 22
sudo ufw allow 'Nginx Full'
sudo ufw enable

Configure the Database

Start the SQL Configuration for MariaDB.

sudo mysql_secure_installation

Follow the wizard and answer the questions as below. There are a few extra steps but they are pretty clear, so work through.

  1. Enter root password?
    Click ENTER. You wont have set one yet. You'll be asked to do so shortly and it will be used down the track.
  2. Remove anonymous users?
  3. Disallow root login remotely?
  4. Remove test database and access to it?
  5. Reload privilege tables now?

Now, grant user root privileges so that Ghost CLI can create the databases automatically (Kudos Ryan Erickson!). You'll need that SQL root password here.

sudo mysql -u root -p

You'll end up in MariaDB shell. Enter the following commands and yes, they are case sensitive and you need the semi-colon.

USE mysql
UPDATE user SET plugin='mysql_native_password' WHERE User='root';

Configure the Web Server

First, enable the hash_bucket_memory_size parameter by removing the comment marker from the nginx.conf file.

sudo nano /etc/nginx/nginx.conf

Whenever you make a change to the config its a good idea to test it.

sudo nginx -t

If passed ok, reload nginx for the changes to take effect. If you do encounter any issues, its usually a typo so go ahead and take another look.

sudo systemctl restart nginx

Install and Configure Ghost

Install Node.js.

Ghost only supports particular versions and this version is recommended at the time of writing. Be sure to check the documentation to ensure you have the optimal version.

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash
sudo apt-get install -y nodejs
Install Ghost CLI
sudo npm i -g [email protected]

Make a new directory for your Ghost install. I have multiple for testing so name appropriate to your use case. Change the user reference (pi:pi) to sort your username.

sudo mkdir /var/www/ghost-prd
sudo chown pi:pi /var/www/ghost
cd /var/www/ghost-prd
Configure Ghost

As before you'll now answer a few questions. These are straight forward. My answers are below, adjust to suit your needs. For details, check out the CLI reference cli-install#section-prompts

  1. Continue anyway?
  2. Enter your blog URL:
  3. Enter your MySQL hostname:
    localhost (or simply press ENTER)
  4. Enter your MySQL username:
  5. Enter your MySQL password:
    (enter your password here)
  6. Enter your Ghost database name:
  7. Do you wish to set up Nginx?
  8. Do you wish to set up SSL?
    No (I used Cloudflare and used the instructions here: Ghost Pi.
  9. Do you wish to set up "ghost" mysql user?
  10. Do you wish to set up Systemd?
  11. Do you want to start Ghost?

Or, you can do it all programmatically in one line. This is my preferred option.
Using Ghost-CLI programatically

Congratulations! You know have a working Ghost installation!

Next Steps

Some things to do,

  • Add SSL functionality through Cloudflare... Check out this article from Ghost Pi
  • Add some security enhancements to MariaDb... Check out this article from Digital Ocean
  • Add some high availability with a Docker Swarm... Research and tinker...
  • Add backup functionality... Research and tinker...

Anything else?

Good luck! I learned a lot going through this excercise and am looking forward to see how we can improve on the solution.

Steve Rackham

Steve Rackham

By day, IT professional with advanced skills across a broad spectrum of technology stacks and enterprise platforms. By night, happiest learning while tinkering under the hood and writing :)

Read More
Blogging with a Slice of Raspberry Pi
Share this