Installing Ghost CMS on Debian 9 Stretch Server with MariaDB

So you decided to try installing Ghost CMS on a Debian based system. And like me, you could not understand why it didn't work right out of the box. Here is something I did to make it work on mine.

While not officially supported, the things done in this short post presented here worked for me, so I hope it works for you too.

Before you Begin

Ensure that your system is up to date and have required system tools:

sudo apt update && sudo apt upgrade
sudo apt install build-essential

This is just so we don't run into any problems during build time.

Installing MariaDB

Now, you might think you can just install MariaDB through apt "mariadb-server", this will in fact give you the wrong version and ghost will not like working with that version. (Guess who did that, and had to go through the fun process of uninstalling it)

  1. First, install the required tools to makes sure it works
sudo apt -y install software-properties-common dirmngr

2.  Next we need to add MariaDB 10.4 repository and Import GPG key into our system. So run the following command. Don't worry, I'm not stealing your server, and this is the official mirror for Maria. (See this website for the official repo).
Note: You could install the 10.5 version, but 10.4 worked for me, and I'd rather not have to reinstall it again. I might update this in the future, if I find that it worked.

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.zol.co.zw/mariadb/repo/10.4/debian stretch main'

3.  Now, after this is added, run this command to actually install MariaDB

sudo apt update && sudo apt install mariadb-server mariadb-client

If prompted to set the root password, just write the password you want to use for the root user. If you are hosting it on somewhere not on your own local computer, DON'T leave it blank, and don't use passwords such as "password", "12345", etc.

If you didn't get a prompt to set the password, don't worry, we can set it later. Instead, lets check if MariaDB has started by running:

sudo  systemctl status mysql

You can also attempt to log in by writing either of these lines

mysql -u root -p
sudo mysql -p

If you didn't get a password prompt, you can just write either of these lines

sudo mysql

If everything works it should show up as something like this:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.4.6-MariaDB-1:10.4.6+maria~stretch mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Note the server version: 10.4.6-MariaDB-1, this is one that works with GhostCMS. Another way of checking the version, write the following in the terminal:

SELECT VERSION();

This will show something like this:

+-------------------------------------------+
| VERSION()                                 |
+-------------------------------------------+
| 10.4.6-MariaDB-1:10.4.6+maria~stretch     |
+-------------------------------------------+
1 row in set (0.001 sec)
MariaDB [(none)]> 

If you DIDN'T get a prompt to set a password after installing MariaDB, if you already have set the password, skip this step.

While still logged into the MariaDB Server, type these lines. Change 'password' to whatever you want it to be. If you have other users or hosting on a separate server, change the 'root@localhost' to what you need it to be.

SET old_passwords=0;
ALTER USER root@localhost IDENTIFIED BY 'password';

Now, click CTRL+C or type QUIT to quit the connection to the SQL. If everything works without problems, you can continue onto the next step

Install and Configure Ghost

Now after you've done all that, you can follow the ghost setup as usual. You can even follow along some more standard guides like the following.

How to Install Ghost CMS on Debian 10
Easily publish your own professional-looking blog using Ghost on your Linode running Debian 10.

Opposite to Linode's guide to configuring it, you should select "no" on the SSL option, as Debian 9 doesn't have an automatic SSL setup. You need to manually do this after fixing the sub-domain config.

Fix hosting on sub-domains

Now, if you're like me, you probably want to install Ghost in a subdomain, rather than the main domain. What I found, was that it was difficult to find out exactly what you need to do for it to work. This is why I'll provide you with my config file:

server {
    listen 80;
    listen [::]:80;

    server_name your.domain.com;
    root /var/www/ghost/system/nginx-root;

    location / {
        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:2369; # alternativly you can use http://localhost:2369
        
    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}

Now, when everything is done, then it should be up and running. Have fun, and send me a message if you still have problems.

PS. If you want your ghost files in another folder, you can change the root text in this line.

root /var/www/ghost/system/nginx-root;

Support Me

Want to support my work, consider supporting me through either of these ways.