DEV Community

Cover image for Hands-on Ghost pt.1 - Become an online publisher step-by-step using your server.
Adam
Adam

Posted on • Updated on

Hands-on Ghost pt.1 - Become an online publisher step-by-step using your server.

Introduction to Ghost 👻 - modern Node.js publishing platform.

Table of contents

First one of the incoming Ghost tutorial series.
The inscription will cover a topic of ghost setup on Ubuntu 18.04, ensuring step by step that prerequisites for installing the Ghost-CLI are met, installing Nginx, MySQL, and nodejs. I will introduce headless CMS of my choice and gather instructions for installing it with all other necessary software and its basic configuration.

Ghost introduction

It's an open-source publishing platform, headless Node.js CMS. Started by John O'Nolan and Hannah Wolfe in early 2013, after successful Kickstarter campaign with the mission to deliver publicly available tools for independent journalists and writers across the world to increase their impact on online media. Not complicated to configure, relatively fast and quite well-designed out-of-the-box. CMS comes with features which can be customized based on the needs. The basic theme is Casper, but it's not complicated to craft your one. As we can read on ghost www - they are structured as a non-profit organization and product based on the needs of its users - not ones who look for returns. The ghost is licensed under MIT LICENCE.

General prerequisites


alt text

Server prerequisites

Ubuntu configuration

Assuming that you already have access to your Ubuntu terminal, let's create a new user

:~$ adduser ghostuser
Enter fullscreen mode Exit fullscreen mode

and add it to the sudo group using usermod with --append & --groups options.

# Usage: usermod [options] LOGIN

:~$ usermod -aG sudo ghostuser
Enter fullscreen mode Exit fullscreen mode

Now we need to set up Uncomplicated Firewall :D
CLI lines speak for themselves I believe, as we could expect from the name.

:~$ ufw allow OpenSSH
:~$ ufw enable
Enter fullscreen mode Exit fullscreen mode
:~$ ufw status
Enter fullscreen mode Exit fullscreen mode

Allowing OpenSSH will let us through the firewall while connecting using the SSH protocol.

:~$ ssh ghostuser@server_ip
Enter fullscreen mode Exit fullscreen mode

NGINX installation

Nginx is available in Ubuntu's default repository, so we can get it using apt.

:~$ sudo apt-get update
:~$ sudo apt-get upgrade
Enter fullscreen mode Exit fullscreen mode
:~$ sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode

The software adds itself to UFW upon installation but as it is recommended we need to enable the most restrictive profile that will still allow the traffic you’ve configured.

:~$ sudo ufw app list
Enter fullscreen mode Exit fullscreen mode
:~$ sudo ufw allow 'Nginx HTTP'
Enter fullscreen mode Exit fullscreen mode

Now you should be able to see Nginx Hello World page at http://server_ip.

MySQL configuration

A headless CMS focus is to store and deliver structured content. Ghost uses MySQL for the content to read and write.

:~$ sudo apt-get install mysql-server
Enter fullscreen mode Exit fullscreen mode
:~$ sudo mysql
Enter fullscreen mode Exit fullscreen mode

As it is on the Ghost docs:

# Now update your user with this password
# Replace 'password' with your password, but keep the quote marks!

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

# Then exit MySQL

quit

# and login to your Ubuntu user again

su - <user>
Enter fullscreen mode Exit fullscreen mode

Nodejs installation

To run Ghost you need to have nodejs repository downloader and installed.

:~$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash

:~$ sudo apt install nodejs
Enter fullscreen mode Exit fullscreen mode

If you met some problems here, please check different installation methods at digitalocean.

The npm CLI.

:~$ sudo apt install npm
Enter fullscreen mode Exit fullscreen mode

Some npm packages to work require compiling code from the source - you will need to install the build-essential package to run them.

:~$ sudo apt install build-essential
Enter fullscreen mode Exit fullscreen mode

Ghost-CLI

Now when you're sure about server met the prerequisites you can proceed to Ghost-CLI installation.

The project goal is to make setting up and maintaining a Ghost site as straight forward as possible. Mainly ensuring that everyone that uses the recommended system stack can install, configure, start, stop, restart, update & list their Ghost sites. It makes possible to install or update Ghost in a single command.

We can get it using npm CLI.

:~$ sudo npm install ghost-cli -g

:~$ ghost help
Enter fullscreen mode Exit fullscreen mode

Install Ghost

Before installing ghost, remember to register your domain. Here we use server-domain.com.

Create a directory, set its owner and permissions.

:~$ sudo mkdir -p /var/www/ghost
:~$ sudo chown <ghostuser>:<ghostuser> /var/www/ghost
:~$ sudo chmod 775 /var/www/ghost
Enter fullscreen mode Exit fullscreen mode

Then navigate to the new directory and install the ghost.

:~$ cd /var/www/ghost
:~$ ghost install
Enter fullscreen mode Exit fullscreen mode

Change your Nginx configuration to display your blog.

:~$ cd /etc/nginx/
:~$ rm sites-enabled/default
:~$ cd sites-available
:~$ touch ghost
Enter fullscreen mode Exit fullscreen mode
server {
        listen 0.0.0.0:80;
        server_name *server-domain-name*;
        access_log /var/log/nginx/*server-domain-name*.log;

        location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:2368;
        proxy_redirect off;
    }
}
Enter fullscreen mode Exit fullscreen mode

Nginx reads from sites-enabled directory during startup, so we need to link that file.

:~$ cd..
:~$ sudo ln -s sites-available/ghost sites-enabled/ghost
Enter fullscreen mode Exit fullscreen mode

As there are possible hash bucket memory problem, but they're easy to solve by editing a single file.

:~$ sudo nano /etc/nginx/nginx.conf
Enter fullscreen mode Exit fullscreen mode
...
http {
    ...
    server_names_hash_bucket_size 64;
    ...
}
...
Enter fullscreen mode Exit fullscreen mode

To be sure we can check for the errors and restart Nginx using commands bellow.

:~$ sudo nginx -t
:~$ sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Start Ghost

:~$ ghost start
Enter fullscreen mode Exit fullscreen mode

SSH

Ghost has integration with Let's Encrypt SSL and thanks to that you can add a new SSL certificate in a couple of steps using a single command.

ghost setup ssl
Enter fullscreen mode Exit fullscreen mode

In the next part, I will cover adding Ghost to upstart to be sure that it runs whenever your server does.
I will also show how to host your blog on Heroku and AWS.
Later I'm going to show how to create a custom theme and more.

Top comments (0)