Author Archives: Elian Lincoln

How to install Ghost on Ubuntu

A full guide for installing, configuring and running Ghost on your Ubuntu 16.04 or 18.04 server, for use in production.


The officially recommended production installation requires the following stack:

  • Ubuntu 16.04 or Ubuntu 18.04
  • NGINX (minimum of 1.9.5 for SSL)
  • A supported version of Node.js
  • MySQL 5.5, 5.6, or 5.7 (not >= 8.0)
  • Systemd
  • A server with at least 1GB memory
  • A registered domain name

Before getting started you should set an A record from the domain you plan to use, pointing at the server’s IP address and ensure that it’s resolving correctly. This must be done in advance so that SSL can be properly configured during setup.

Server Setup

This part of the guide will ensure all prerequisites are met for installing the Ghost-CLI.

Create a new user

Open up your terminal and login to your new server as the root user:

# Login via SSH
ssh root@your_server_ip

# Create a new user and follow prompts
adduser <user>

Note: Using the user name ghost causes conflicts with the Ghost-CLI, so it’s important to use an alternative name.

# Add user to superuser group to unlock admin privileges
usermod -aG sudo <user>

# Then log in as the new user
su - <user>

Update packages

Ensure package lists and installed packages are up to date.

# Update package lists
sudo apt-get -y update

# Update installed packages
sudo apt-get -y upgrade

Follow any prompts to enter the password you just created in the previous step.

Install NGINX

Ghost uses an NGINX server and the SSL configuration requires NGINX 1.9.5 or higher.

# Install NGINX
sudo apt-get install -y nginx

# Delete the default configuration file
sudo rm -rf /etc/nginx/sites-available/default
sudo rm -rf /etc/nginx/sites-enabled/default

# Restart NGINX
sudo service nginx restart

If ufw was activated, the firewall allows HTTP and HTTPS connections. Open Firewall:

# Allow NGINX
sudo ufw allow 'Nginx Full'

Or, allow specific ports:

# Allow Ghost
sudo ufw allow 2368

If ufw was not installed, you can install it:

sudo apt-get install -y ufw

After the above operations are performed, reload UFW

# Reload UFW
sudo ufw reload

Install MySQL

Next, you’ll need to install MySQL to be used as the production database.

# Install MySQL
sudo apt-get install -y mysql-server

MySQL on Ubuntu 18.04

If you’re running Ubuntu 18.04, a password is required to ensure MySQL is compatible with Ghost-CLI. This requires a few extra steps!

# To set a password, run
sudo mysql

# 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

# and login to your Ubuntu user again
su - <user>

Install Node.js

You will need to have a supported version of Node installed system-wide in the manner described below. If you have a different setup, you may encounter problems.

# Add the NodeSource APT repository for Node 10
curl -sL | sudo -E bash

# Install Node.js
sudo apt-get install -y nodejs

Install Ghost-CLI

Ghost-CLI is a commandline tool to help you get Ghost installed and configured for use, quickly and easily. The npm module can be installed with npm or yarn.

# Install Ghost-CLI
sudo npm install ghost-cli@latest -g

Once installed, you can always run ghost help to see a list of available commands.

Install Ghost

Once your server is correctly setup and the ghost-cli is installed, you can install Ghost. The following steps are the recommended setup. If you would prefer more fine-grained control, the CLI has flags and options that allow you to break down the steps and customise exactly what they do.

Note: Installing Ghost in the /root or home/<user> directories results in a broken setup. Always use a custom directory with properly configured permissions.

Create a directory

Create a directory for your installation, then set the owner and permissions.

# We'll name ours 'ghost' in this example; you can use whatever you want
sudo mkdir -p /var/www/ghost

# Replace <user> with the name of your user who will own this directory
sudo chown <user>:<user> /var/www/ghost

# Set the correct permissions
sudo chmod 775 /var/www/ghost

# Then navigate into it
cd /var/www/ghost

Run the install process

Now you’ve made it this far, it’s time to install Ghost with a single command 😀

# Install Ghost
ghost install

Once the install is finished you’ll be able to access your new site and navigate to /ghost to access Ghost Admin ✨

This article is excerpted and perfected from the official Ghost documentation.

Some practical tools for linux operation and maintenance

NameWhat is this and what does it doAliyun YUMAliyun APT
NethogsView the process’ bandwidth usageYesYes
IOZoneHard drive read performance test
IOTopHard disk real-time monitoringYesYes
IPtrafNetwork traffic monitoringYesYes
IFTopNetwork traffic monitoringYesYes
HTopProcess real-time monitoringYesYes
NMONSystem resource monitoringYesYes
MultiTailMonitor multiple logsYesYes
Fail2banSSH brute force protectionYesYes
TmuxTerminal multiplexerYesYes
AgeduPage shows disk space usageYesYes
NMapSecurity scan toolYesYes
HttperfWeb stress testYesYes