Install and Configure a Ghost v1.0.0 Blog on Ubuntu 16.04

Ghost is a modern, open source publishing platform built on Node.js with an Ember.js admin client, a JSON API, and a theme API powered by Handlebars.js. Ghost team recently released a new version of Ghost with a lot of new features and improvements: new markdown editor with the toolbar to help you with styling your post, UI/UX improvements, drag and drop multiple images,
improved installation and update process with new tool called Ghost-CLI, new default theme Casper v2.0.0 and much more. I leave it to you to explore more after you install it.

In this tutorial we are going to install, setup and configure a Ghost v1.0.0 on Ubuntu 16.04 LTS using MySQL, Let’s Encrypt, Node.js, NPM, Ghost-CLI and NGINX.

NOTE: Ubuntu 16.04 LTS is the only officially supported Linux distribution. It is not possible to install Ghost v1.0.0 on other Linux distributions. In future, it will probably be possible to install it when they add support for other distributions in Ghost-CLI tool.

Ghost team recommends the following server stack and setup for production installation of Ghost v1.0.0 blog:

  • Ubuntu 16.04 as the operating system with minimum 1GB of RAM (swap can be used)
  • Systemd (to manage the Ghost process)
  • MySQL as the recommended database engine
  • NGINX (minimum of 1.9.5 for SSL)
  • Node.js v6 installed via NodeSource repository
  • NPM or Yarn package manager
  • C++ compiler
  • A non-root user for running ghost commands

Before you Begin #

  1. Check Ubuntu version:
    lsb_release -ds
    # Ubuntu 16.04.3 LTS
  2. Create a new non-root user account with sudo access and switch to it:

    NOTE: Replace johndoe with your username

    adduser johndoe --gecos "John Doe"
    usermod -aG sudo johndoe
    su - johndoe
  3. Set up the timezone:
    sudo dpkg-reconfigure tzdata
  4. Ensure that your system is up to date:
    sudo apt update && sudo apt upgrade -y
  5. Install build-essential package:
    sudo apt install -y build-essential

Step 1 – Install MySQL #

First, we will need to install MySQL database as Ghost recommends it as database for production environment.

  1. Download and install MySQL:
    sudo apt install -y mysql-server

    NOTE: You will be prompted to enter password for the MySQL “root” user. Enter strong password!

  2. Check MySQL version:
    mysql --version
    # mysql  Ver 14.14 Distrib 5.7.19, for Linux (x86_64) using  EditLine wrapper
  3. Harden MySQL Server by running mysql_secure_installation script:
    sudo mysql_secure_installation

Step 2 – Install NGINX #

Next, we need to install NGINX software. It will be used as a reverse proxy for our Ghost application. Ghost-CLI can configure NGINX as a reverse proxy for you automatically.

  1. Download and install NGINX:
    sudo apt install -y nginx
  2. Check NGINX version:
    sudo nginx -v
    # nginx version: nginx/1.10.3 (Ubuntu)

Step 3 – Install Node.js and NPM #

Ghost v1.0.0 currently supports Node.js versions 6.9+ and 4.5+ only. The recommended version of Node.js to use with Ghost v1.0.0 is currently Node.js v6 Boron LTS.

Ghost is built on Node.js. Ghost is following Node’s LTS plan, only supporting LTS versions of Node.js. So, we will need to install latest LTS version of Node.js.

  1. Download and install Node.js and NPM:
    curl -sL | sudo -E bash -
    sudo apt install -y nodejs
  2. Check Node.js and NPM version:
    node -v && npm -v
    # v6.11.3
    # 3.10.10

Step 4 – Install Ghost-CLI #

Ghost-CLI is a CLI tool for installing and updating Ghost. It makes installing and updating Ghost easy. It can set up database for you, configure NGINX as a reverse proxy, set up TLS security by using Let’s Encrypt, automatic SSL renewal and set up ghost as a systemd service. It will take care of basic security for you, by creating dedicated system user called ghost for running Ghost blog.

  1. Install Ghost-CLI via npm:
    sudo npm install -g [email protected]
  2. Check Ghost-CLI version:
    ghost version
    # Ghost-CLI version: 1.1.1
  3. Run ghost doctor command to check that your environment is compatible with Ghost-CLI:
    ghost doctor
    ✔ Checking system Node.js version
    ✔ Checking current folder permissions
    ✔ Checking operating system
    ✔ Checking MySQL is installed
    ✔ All install checks passed
  4. Get help about ghost command:
    ghost help
  5. To get more specific help about ghost subcommands you can run ghost help <command>. For example to get help about ghost config command, run:
    ghost help config

Step 5 – Install Ghost #

NOTE: Make sure DNS records for your domain are set up. This tutorial uses example domain blog.example.tld. Replace blog.example.tld with your domain/hostname.

Now we are ready to install Ghost CMS. The only way to install Ghost v1.0.0 is by using Ghost-CLI tool.

  1. Create document root directory:
    sudo mkdir -p /var/www/ghost
  2. Change the ownership of the /var/www/ghost directory to the non-root user with sudo privileges that you have created in the beginning of this tutorial:
    sudo chown <johndoe>:<johndoe> /var/www/ghost
  3. Navigate to document root directory:
    cd /var/www/ghost

    NOTE: Make sure /var/www/ghost directory is empty before installing Ghost and your user must own this directory.

  4. Install Ghost in a production mode:
    ghost install
  5. Answer the questions it prompts with. For more information about questions it prompts visit Ghost docs:
    ? Enter your blog URL: https://blog.example.tld
    ? Enter your MySQL hostname: localhost
    ? Enter your MySQL username: root
    ? Enter your MySQL password: [Enter password you created when you installed MySQL]
    ? Enter your Ghost database name: [Whatever you want]
    ? 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) [Your email for Let's Encrypt]
    ? Do you wish to set up "ghost" mysql user? yes
    ? Do you wish to set up Systemd? yes
    ? Do you want to start Ghost? yes

    NOTE: After installation, NGINX configuration files will be in /var/www/ghost/system/files directory. Ghost-CLI will ask you Do you wish to set up Nginx? and if your answer is yes, then it will configure NGINX as a reverse proxy for you automatically. Your NGINX config files will be in {your_ghost_installation_dir}/system/files directory.

  6. After installation is complete you can run ghost ls to view running Ghost process:
    ghost ls
  7. Also to check if Ghost is installed you can run ghost version again from /var/www/ghost directory:
    ghost version
    # Ghost-CLI version: 1.1.1
    # Ghost Version (at /var/www/ghost): 1.8.4
  8. In future when newer version of Ghost is released just run ghost update command in from /var/www/ghost directory to update ghost. Also, before updating make a backup of you blog from admin interface.
  9. To complete the setup process and create Ghost admin account, navigate to the Ghost configuration page by appending /ghost to the end of your blog’s URL. This example uses https://blog.example.tld/ghost.

Conclusion #

We have successfully installed and configured our new Ghost v1.0.0 blog for production. Ghost-CLI tool makes our life much easier by eliminating manual steps we had to do with older v0.11.x Ghost. You can also do everything manually without the help of Ghost-CLI tool but you will lose the ability to easily update your blog with ghost update command. Doing everything manually is laborious and not recommended. The only downside is the fact that other Linux distributions are not supported at this moment.

Powered by BetterDocs