How to install ghost on a dedicated server or a VPS ?

Install Ghost on your server in a few minutes with this easy to follow guide.

Ghost is a nice alternative to WordPress, which like its counterpart allows you to publish content on a blog. You can transform this blog into a personal blog, a magazine, a documentation space, etc... We, at Primates, use ghost instead of wordpress for our blog.

The installation is fairly quick but is not a simple task for everyone.

Here is, therefore, how to host and install a blog with Ghost on a dedicated server, or a VPS, with Ubuntu 18.04 (it doesn't change much from one Linux distribution to another).

Prerequisites for installing Ghost :

  • Ubuntu 16.04 or Ubuntu 18.04
  • NGINX (minimum 1.9.5 for SSL)
  • A supported version of NodeJS
  • MySQL
  • Systemd
  • A server with at least 1 GB of memory
  • A registered domain name. Before continuing, you need to set a CNAME or A record on the domain name you plan to use, pointing to the IP address of the server and make sure it resolves correctly.
How to point a domain name to a server?
Whether you are hosting a website or a Webapp and want to access it quickly, you’ll have to use a domain name. A domain name makes it easy for you and users to find your website.

This must be done in advance so that Let's Encrypt can install the SSL certificate (useful for your blog to be available in "https") when installing Ghost.

Before installing Ghost on your machine, remember to do the updates!

SSH connection from the terminal

ssh root@<ip_of_the_machine>

Updating the package list

sudo apt-get update

Updating installed packages

sudo apt-get upgrade

Create a new user on your machine Open your terminal and log in to your new server as "root" user:

Adding a new user

adduser <user>

Add this new user to the super-users

usermod -aG sudo <user>

Login with this new user

su - <user>


Ghost uses an NGINX server as a proxy, to link the launched NodeJS instance, and the domain name, and it allows to use an SSL certificate on the application. Install it with the following command :

Install NGINX

sudo apt-get install nginx

If you use a firewall such as UFW (Uncomplicated Firewall) on your machine, remember to allow the port used by NGINX (80 and 443, for http, and https).

Adding NGINX ports to the firewall

sudo ufw allow 'Nginx Full'

Install MySQL

sudo apt-get install mysql-server 

After MySQL installation, remember to change the password of the main account (i.e. "root"), in order to secure access to MySQL as much as possible.

Login to MySQL from the command line

sudo mysql

Replace 'password' with the new password

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

Exit MySQL

quit

Reconnect to your account on Ubuntu

su - <user>

Ghost recommends to install some versions of NodeJS.

Add NodeJS repository in version 12.x

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

Install NodeJS

sudo apt-get install -y nodejs

Install Ghost CLI Ghost-CLI is a command-line tool to help you install and configure Ghost quickly and easily. The NPM (Node Package Manager) module can be installed with npm or yarn.

Install Ghost CLI

sudo npm install ghost-cli@latest -g

Once installed, you can still run ghost help to see a list of commands available on Ghost. Among them, you will find commands to start or stop Ghost, to import or export blog settings, etc...

We now come to the most important step of this article, namely, the installation of Ghost on your dedicated machine or VPS. The installation is easy but, as I told you at the beginning of the article, to get here, it is not given to everyone.

Create your Ghost blog directory in /var/www/

sudo mkdir -p /var/www/ghost

Give your user access rights to the directory

sudo chown <user>:<user> /var/www/ghost

Give read/write permission to the directory

sudo chmod 775 /var/www/ghost

Go to this directory

cd /var/www/ghost

Finally, we're getting there!

To install Ghost, make sure you are in the previously created directory and run this command :

Install Ghost

ghost install

Answer the questions you are asked:

  • Blog URL
  • MySQL host name (localhost)
  • MySQL username (root)
  • MySQL root password
  • MySQL database name

It is recommended to use MySQL username generator. This will generate a MySQL username and password for your new installation of Ghost. Let the installer configure NGINX and the SSL certificate (you will be asked your email for certification), then let Systemd configure automatically.

Finally, choose whether or not to start Ghost.

You can start Ghost later with this command :

ghost start

Go now to the URL of your blog, you will access a page with pre-written articles on a theme called Casper. To remove these articles, and start on a good basis, add "/ghost" at the end of the URL. You will access the administration interface which will ask you to create an account (the first account created becomes the blog administrator).