How to install Ghost on Ubuntu 18.04 (Tutorial)

Ghost CMS: How to install on your Ubuntu 16.04 VPS

Getting started with Ghost CMS on Ubuntu 18.04

Today we’ll walk you through how to install Ghost on your VPS using Ubuntu 18.04 or Ubuntu 16.04.

The Ghost CMS is simple, elegant, and responsive platform for blogging. Unlike WordPress, the Ghost CMS is meant exclusively for blogging– so it’s not set up to handle something more extensive, like an e-commerce website.

Why install Ghost CMS over other content management systems?

The Ghost CMS has a no-nonsense style that appeals to people who just want a simple blogging platform that looks great. There are minimal themes and an uncluttered design, so you can get right to writing instead of finding your way through a cluttered dashboard and thousands of plugins.

Ghost is a modern, open source blogging platform written in NodeJS. The Ghost CMS come with a brand new Markdown editor, a refreshed UI, a new default theme design, and a lot more features that make for a nicer blogging experiencing.

Installing Ghost CMS is pretty straightforward and Ghost officially recommends the following stack and server setup:

    • Ubuntu 18.04
  • MySQL
  • NGINX
  • Systemd
  • NodeJS
  • At least 1GB memory
  • A non-root user for running ghost commands

Source: Ghost

Prerequisites for your Ghost CMS install

  • A VPS running Ubuntu 18.04 (or Ubuntu 16.04)
  • A non-root, sudo-enabled user. If you only have a root user, see our SSH tutorial for details on creating new users.
  • A registered domain name.
  • A DNS A record that points to your server’s IP address based on the FQDN you want to use. For example, an A record named test would point to test.DOMAIN.TLD.

Notes

  • This tutorial requires the use of domain names. Whenever you see either the SUBDOMAIN, DOMAIN, or TLD variables, replace them with the details of your domain name. In example.ssdnodes.com, example is the SUBDOMAIN, ssdnodes is the DOMAIN, and .com is the TLD.
  • This tutorial requires the use of passwords. Whenever you see the PASSWORD variable, then replace it with your own.

Getting your server ready to install Ghost CMS

Ghost is built on NodeJS, and the latest release of Ghost supports NodeJS versions 10.x and 8.x only. You can pick either of the NodeJS versions, but for this tutorial, we will use NodeJS version 10. To install it, add the NodeSource APT repository to your server first.

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

Now install NodeJS with the following apt command:

$ sudo apt install nodejs

Check the version of Node and NPM:

$ node -v && npm -v
v10.16.3
6.9.0

Click here for a more detailed tutorial on how to install NodeJS on Ubuntu 18.04

Install MariaDB and create a database

Ghost supports either MySQL/MariaDB or SQLite databases. However, for this tutorial, we will be using the MariaDB database. You can also opt for MySQL instead of MariaDB.

Install the latest stable release of MariaDB server on your system by using following apt command:

$ sudo apt install mariadb-server

Next, run mysql_secure_installation to configure a few settings of MariaDB like updating the root password, removing the test database, and more, to make it secure.

$ sudo mysql_secure_installation

Once the MariaDB server is installed and configured in your server, create a user and a database especially for Ghost. To do that, log in to the MariaDB server using mysql -u root -p command and complete the steps as described below.

$ mysql -u root -p
Enter password:

MariaDB [mysql]> CREATE DATABASE blog;
Query OK, 1 row affected (0.00 sec)

MariaDB [mysql]> CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'PASSWORD';
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> GRANT ALL ON blog.* TO 'ghostuser'@'localhost' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit

Install Nginx

Ghost runs on port 2368, which is different from standard web server port 80 typically employed by either Apache or Nginx. To direct traffic to Ghost, you need to configure a proxy server that will act as a front end. Ghost officially recommends Nginx as a proxy server, although you can use Apache to do the same job. To install Nginx, issue the following command from the terminal:

$ sudo apt install nginx

Install Ghost-CLI

Ghost-CLI is a command line interface (CLI) tool to install and update Ghost in the terminal. Ghost-CLI makes it easy to install Ghost CMS by selecting the database, configuring NGINX as a reverse proxy, setting up a Let’s Encrypt SSL certificate, and creating a systemd service with a single command.

The objective of the Ghost CLI project is to make setting up and maintaining a Ghost site as straightforward as possible for people who do not want to use Ghost(Pro).
Source: Ghost-CLI

Since Ghost-CLI is an NPM module, it can be installed using either npm or yarn. We will use npm to install it.

$ sudo npm install -g [email protected]

Check the version of Ghost-CLI using following command:

$ ghost -v
Ghost-CLI version: 1.11.0

Install Ghost

To install Ghost, navigate to the /var/www/html and create a folder for it.

$ cd /var/www/html
$ sudo mkdir -p /var/www/html/blog

Note: Installing Ghost in the /root or /home/USER folder won’t work and result in a broken setup! Please only use /var/www/html because it has the right permissions.

Once you’re done with creating the installation folder for Ghost, change the ownership of the folder to a non-root, sudo-enabled user. The installation of Ghost will not proceed if the ownership of the newly created folder remains with root user. For this tutorial, we have created a non-root, sudo-enabled user by the name bloguser. Check this tutorial to create a non-root, sudo-enabled user.

Note: Don’t give this new user the name ghost! Ghost-CLI will create a ghost user for managing the blog during installation.

$ sudo chown bloguser:bloguser /var/www/html/blog

Next, assign correct permissions to the installation folder.

$ sudo chmod 775 /var/www/html/blog

Change to the shell of the non-root user and subsequently navigate to the Ghost installation folder /var/www/html/blog to install it.

$ su - bloguser
$ [email protected]: cd /var/www/html/blog/

Now install Ghost using Ghost-CLI.

ghost install

Answer the prompts as followed:

? Enter your blog URL: https://DOMAIN.TLD
? Enter your MySQL hostname: localhost
? Enter your MySQL username: ghostuser
? Enter your MySQL password: PASSWORD
? Enter your Ghost database name: blog
? Do you wish to set up "ghost" mysql user? no
? Do you wish to set up Nginx? yes
? Do you wish to set up SSL? yes
? Enter your email (used for Let's Encrypt notifications) [email protected]
? Do you wish to set up Systemd? yes
? Do you want to start Ghost? yes

Your Ghost installation should be finished at this point! You can now access it via https://DOMAIN.TLD or https://SUBDOMAIN.DOMAIN.TLD, depending on your particular configuration.

Complete the Ghost CMS install & setup

To complete the setup process, point your browser to the Ghost CMS configuration page at https://DOMAIN.TLD/ghost.

STEP 1

Click Create your account.

STEP 2

Fill up all the details, like the blog’s title, your name, email address, and password. The email address and password will be used by Ghost to authenticate the admin user at later stages. Once done click Invite your team to add more members to your team.

STEP 3

Or, click the I’ll do this later, take me to my blog! link to visit the admin section and change your site’s theme or configure additional settings.

Your installation of Ghost CMS is complete!

You can now start blogging with this awesome platform. Consult the official documentation for theming instructions and other configurations.

 

Changelog:

Oct 2, 2019: Updated to work with Ubuntu 18.04