[Ghost CMS | en] Install Ghost CMS on a Raspberry Pi

In this tutorial, I'll guide you through setting up Ghost CMS on a Raspberry Pi. I'll assume that you're familiar with the command line and you've got the latest version of Raspbian OS installed.

What is Ghost?

Ghost is a really light weight blogging CMS. It was devised due to the founder's frustration with the increasingly bloated WordPress CMS. Ghost is written in Javascript unlike WordPress, which is written (badly) in PHP.

Step-by-step install Ghost CMS on Raspberry Pi

Let's strictly follow these below steps:

1. Make sure system up-to-date and get enough packages

Step 1.1 - Ensure we're using the most up-to-date version of node:

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash

Step 1.2 - Ensure we're up-to-date with all the system updates.

sudo apt update -y && sudo apt upgrade -y

Step 1.3 - Install MariaDB as the database server and Nginx as the web server.

sudo apt install nginx mariadb-server nodejs -y

Step 1.4 - Let's globally install ghost:

sudo npm install ghost-cli@latest -g

2. Configure MariaDB database

Step 2.1 - Stop the database server:

sudo service mariadb stop

Step 2.2 - Restart the server in safe mode:

sudo mysqld_safe --skip-networking &

Step 2.3 - Login to MariaDB:

sudo mariadb -u root

Step 2.4 - Reload the grant tables using this command:

FLUSH PRIVILEGES;

Step 2.5 - Set your password for the root user, changing my_root_password for one of your choice:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'my_new_password';

Step 2.6 - Flush privileges again:

FLUSH PRIVILEGES;

Step 2.7 - Exit out of MariaDB:

exit

Step 2.8 - Restart your Pi:

sudo reboot

3. Create a database and database user for Ghost

Step 3.1 - Login to MariaDB using our newly created password:

mariadb -uroot -p

You should be asked to enter your password at this point.

Step 3.2 - Create a new user for ghost:

CREATE DATABASE ghost_cms;

Step 3.3 - Change my_password for one of your choice. Bear in mind, we need to remember this password long term, so make it secure.

CREATE USER 'ghost_cms'@'localhost' IDENTIFIED BY 'my_password';

Step 3.4 - Grant our new permissions for our new user on our new database:

GRANT ALL PRIVILEGES ON ghost_cms.* TO 'ghost_cms'@'localhost';

Step 3.5 - Flush the privileges:

FLUSH PRIVILEGES;

Step 3.6 - Exit out of MariaDB:

exit

4. Creating a system user for Ghost

We'll create a new user to administer ghost from. We can't use 'ghost' for this, as it conflicts with the user which Ghost runs under. I use 'www-ghost'.

Step 4.1 - Create a new user to administer ghost from:

sudo useradd www-ghost

Step 4.2 - Add our new user to the sudoers list:

sudo usermod -aG sudo www-ghost

Step 4.3 - Create a home directory for our new user and assign it the correct permissions:

mkdir /home/www-ghost && chown www-ghost:www-ghost /home/www-ghost

Step 4.4 - Create a password for our new user:

sudo passwd www-ghost

You'll be asked for the new password, and to confirm it.

5. Set Ghost up

We'll install ghost to a directory called 'ghost' in our web root. You can change the directory name if you wish.

Step 5.1 - Create ghost directory in folder /var/www/

sudo mkdir -p /var/www/ghost

Step 5.2 - Set the owner of the directory to our ghost user, set the correct permissions and change to the directory:

sudo chown www-ghost:www-ghost /var/www/ghost && sudo chmod 775 /var/www/ghost && cd /var/www/ghost

Step 5.3 - Switch to our newly created Ghost user:

sudo su www-ghost

Step 5.4 - Install ghost:

ghost install

You'll see a message about compatibility. Hit 'y' to continue.

The installation will now begin. It's an interactive installer, so you'll be asked to provide some details. This will take a while depending on the speed of your SD card, so hold tight.

You'll be asked for some more settings, here's a summary of what you should enter:

blog URL: http://localhost:2368     [press enter]
MySQL hostname: localhost           [press enter]
MySQL username: ghost_cms
MySQL password: Whatever password you chose when making the user in MariaDB
Ghost 
database name: ghost_cms
Do you wish to set up Nginx?: y
Do you wish to set up SSL?: n
Do you wish to set up Systemd?: y
Here's a recap of my settings to this point:
You'll be asked if you want to set up nginx, choose 'y' for this, when asked about setting up SSL choose 'n' and finally when asked about systemd choose 'y' again.

Systemd is the system daemon manager and will automatically start the Ghost instance when the Raspberry Pi restarts, or if Node crashes.
Once setup has completed, you'll see the following:

6. Set Ghost up

Finally, we need to get rid of the default configuration for Nginx and restart the service. This can be done with this command:

sudo rm /etc/nginx/sites-available/default && sudo service nginx restart

Let's give it a go!

Enjoy

You're done. You can now manage your blog from your browser. If you're on your Raspberry Pi, simply visit http://localhost:2368/ghost. You will now be left to set things up.

Recap

We've successfully got Ghost CMS running on a Raspberry Pi. These little machines are more than capable of running Ghost CMS. In my tutorial, I installed on a Raspberry Pi 3 Model B which has more than enough power to run Ghost. It will run without any issues on a Raspberry Pi 2 and 4 as well.