Install & Setup (production)

How to install Ghost on your production server

This guide is intended for self hosters, looking for a step-by-step guide to getting Ghost installed, setup and configured on their own servers

If you're looking to install Ghost on your local machine, perhaps just to test it out or to develop a theme, please follow the local install guide instead. If you're looking to hack core files, or even better, contribute, please follow the instructions in Working with Ghost.


This guide will first walk you through how to setup a server with all of our recommended prerequisites. Then we'll show you how to install Ghost CLI and then how to use Ghost CLI to install and setup Ghost.

The CLI Knowledge Base contains detailed information about what Ghost CLI does, and our command reference explains all of the commands that Ghost CLI makes available to you. Finally, if you run into trouble, please see our troubleshooting guide for some solutions to common problems.

Pre-requisites

For installing on production, we officially recommend the following stack:

  • Ubuntu 16.04
  • MySQL
  • NGINX (minimum of 1.9.5 for SSL)
  • Systemd
  • Node v6 installed via NodeSource
  • At least 1GB memory (swap can be used)
  • A non-root user for running ghost commands

Please see the hosting guide for more information on the recommended stack and choosing a hosting provider.

SSL pre-requisites

If you plan to setup SSL, you will need to point your custom domain at your server & check that it is resolving before starting the install.

Minimum NGINX Version

The SSL configuration that will be setup for your ghost blog will pull in a dependency on HTTP/2 (preferred protocol) and thus default setup without modifications requires NGINX 1.9.5.

Check your NGINX version via

nginx -v

Server Setup

The following is a step-by-step guide to installing all of Ghost-CLI's pre-requisites.

Create a New User

When you first log into your new server it is highly recommended to create a new user with regular account privileges and do some basic system setup.

adduser <user>

Super User Privileges

The newly created user has regular account privileges, however, you may sometimes need to do administrative tasks. To not have to log out and in again for these tasks the user is added to the "superuser" group. This allows you to run single commands with super user privileges by using the sudo (superuser do) command.

usermod -aG sudo <user>

Log in as the new user

su - <user>

It is assumed that all following steps are executed by a non-root user. Therefore administrative tasks are shown with sudo where needed.

Basic Security

ghost-cli will create a new system user for running Ghost automatically. This user is called ghost. Ownership of the Ghost content directory will be transferred to ghost. More information can be found in the CLI Knowledge Base. This is a security measure. If Ghost gets compromised, your system would be safe.

After you have created your server, please follow this recommended tutorial to perform some additional system hardening steps (e.g.: public key authentication, firewall).

Update Packages

Before starting with the installation make sure that your package lists and the installed packages are up to date.

Update package lists

sudo apt-get update

Upgrade installed packages

sudo apt-get upgrade

Install NGINX

Install NGINX Webserver on your droplet

sudo apt-get install nginx

Open Firewall for HTTP/HTTPS

If ufw was activated we need to make sure that the firewall allows HTTP and HTTPS connections.

sudo ufw allow 'Nginx Full'

Install MySQL

The CLI installs Ghost by default with MySQL. This is our recommended database. If you would like to use Sqlite3, you can skip this step.

Install MySQL

sudo apt-get install mysql-server

Install Node.js

Add the NodeSource APT repository for Node 6

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

Finally install Node.js

sudo apt-get install -y nodejs

Warning

If you have Node.js already installed, please ensure it was installed system wide. A system wide installation means Node.js was installed e.g. in /usr/bin/node or /usr/local/bin/node. You can double check where Node.js was installed with the command which node.

NVM Warning

If you installed node via nvm, we highly recommend that you uninstall nvm. There have been several people who have run into permission problems, because they've installed nvm in /root or /home, which is a local installation of node. Ghost requires a system wide installation.

It is not enough to symlink the local installation to /usr/bin/node.

Please uninstall nvm and any node versions installed with it:

rm -rf $NVM_DIR ~/.npm ~/.bower
unset NVM_DIR;
which node;
rm -rf {path_to_node_version}

Also look in your ~/.bash_profile or ~/.bashrc and remove any nvm lines.

Install Ghost-CLI

sudo npm i -g ghost-cli

Note

ghost-cli@latest will ensure the latest version, handy for an upgrade or if you're not sure if you already have it installed.

Note

After installing the ghost-cli, you should have global access to ghost in your terminal. Try ghost help.

Install Ghost via the CLI

Be prepared

If you install Ghost via the CLI for production, you need to have met the pre-requisites and installed ghost-cli.

Also, it's important to read through this guide first. This will explain all the steps the CLI will prompt you.

Create a new folder

sudo mkdir -p /var/www/ghost

Danger Zone

Installing Ghost in the /root folder won't work and result in a broken setup!

Your user must own this directory

sudo chown [user]:[user] /var/www/ghost

Where [user] is the user you created during the setup phase.

Navigate to the new folder

cd /var/www/ghost

Make sure directory is empty

You have to run ghost within the directory you would like to install Ghost. Furthermore the directory has to be empty.

Install Ghost (using Ghost-CLI)

ghost install

  • This will install and start your blog in production mode using MySQL as the default database
  • If you want to install Ghost with Sqlite3, please read how here
  • Checkout our detailed prompts guide, which explains all the questions you'll be asked during install.

Ghost-CLI Knowledge Base

If you want to find out more about permissions, certificates/Let's Encrypt or system process check our CLI Knowledge Base

Ghost-CLI commands

If you want to find out more information about a specific Ghost-CLI command, check out our Ghost-CLI API page.

What to do when an install fails

Our troubleshooting guide has a list of potential errors and how to deal with them. If an install goes horribly wrong, you can use ghost uninstall to remove it and try again.

Using ghost uninstall is preferable to deleting the folder, as it will ensure there are no artefacts left behind.

Ghost Admin + Cloudflare

If Ghost admin isn't loading for you, and you have Cloudflare enabled, please read this.

Install & Setup (production)

How to install Ghost on your production server