Hands-on Ghost pt.1 - Become an online publisher step-by-step using your server.
Tags: javascript, node, ubuntu, tutorial
Published: 2020-01-19 21:47:53

<!-- #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

###

- [Ghost introduction](#ghost-introduction)
- [General prerequisites](#general-prerequisites)
- [Server prerequisites](#server-prerequisites)
  - [Ubuntu configuration](#ubuntu-configuration)
  - [NGINX installation](#nginx-installation)
  - [MySQL configuration](#mysql-configuration)
  - [Nodejs installation](#nodejs-installation)
- [Ghost-CLI](#ghost-cli)
- [Install Ghost](#install-ghost)
  - [Start Ghost](#start-ghost)
  - [SSH](#ssh)

##

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](https://github.com/TryGhost/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](https://twitter.com/johnonolan) and [Hannah Wolfe](https://twitter.com/erisds) in early 2013, after successful [Kickstarter campaign](https://www.kickstarter.com/projects/johnonolan/ghost-just-a-blogging-platform/description) 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](https://ghost.org/docs/concepts/features/) which can be customized based on the needs. The basic theme is [Casper](https://github.com/TryGhost/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](https://ghost.org/about/) and product based on the needs of its users - not ones who look for returns. The ghost is licensed under [MIT LICENCE](https://en.wikipedia.org/wiki/MIT_License).

## General prerequisites

- [Ubuntu](https://ubuntu.com/)
- [NGINX](https://www.nginx.com/)
- [MySQL](https://www.mysql.com/)
- [Node.js](https://nodejs.org/en/)
- [systemd](https://systemd.io/)
- 1GB memory
- registered domain name

---

##

![alt text](https://pbs.twimg.com/media/Bg8k3ZzIgAAQ8iy?format=png&name=900x900 "The Joy of Programming with Bob Ross")

## Server prerequisites

###

### Ubuntu configuration

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

```
:~$ adduser ghostuser
```

and add it to the _sudo_ group using _usermod_ with --append & --groups options.

```
# Usage: usermod [options] LOGIN

:~$ usermod -aG sudo ghostuser
```

Now we need to set up [Uncomplicated Firewall](https://help.ubuntu.com/community/UFW) :D
CLI lines speak for themselves I believe, as we could expect from the name.

```
:~$ ufw allow OpenSSH
:~$ ufw enable
```

```
:~$ ufw status
```

Allowing [OpenSSH](https://www.openssh.com/) will let us through the firewall while connecting using the SSH protocol.

```
:~$ ssh ghostuser@server_ip
```

### 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
```

```
:~$ sudo apt install nginx
```

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
```

```
:~$ sudo ufw allow 'Nginx HTTP'
```

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
```

```
:~$ sudo mysql
```

As it is on the [Ghost docs](https://ghost.org/docs/install/ubuntu/):

```
# 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>
```

### 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
```

If you met some problems here, please check different installation methods at [digitalocean](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04).

The npm CLI.

```
:~$ sudo apt install npm
```

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
```

## Ghost-CLI

Now when you're sure about server met the prerequisites you can proceed to [Ghost-CLI](https://github.com/TryGhost/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
```

## 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
```

Then navigate to the new directory and install the ghost.

```
:~$ cd /var/www/ghost
:~$ ghost install
```

Change your Nginx configuration to display your blog.

```
:~$ cd /etc/nginx/
:~$ rm sites-enabled/default
:~$ cd sites-available
:~$ touch ghost
```

```
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;
    }
}
```

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
```

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
```

```
...
http {
    ...
    server_names_hash_bucket_size 64;
    ...
}
...
```

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

```
:~$ sudo nginx -t
:~$ sudo systemctl restart nginx
```
### Start Ghost

```
:~$ ghost start
```
### SSH

Ghost has integration with [Let's Encrypt](#https://letsencrypt.org/) SSL and thanks to that you can add a new SSL certificate in a couple of steps using a single command.

```
ghost setup ssl
```



##

###

---

###

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.