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 gets up to, 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
  • 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.

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).

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

or use yarn (>= 0.23.x): sudo yarn global add 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 /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

Navigate to the new folder

cd /var/www/ghost

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 guide, which explains all installation steps

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.

Ensure pre-requisites are met

You need to ensure all pre-requisites are met prior to attempting a production install, including ensuring your domain DNS record is pointing correctly to your server ip.

SystemD and linux user required

The default production installation requires setting up systemd and a ghost ubuntu user. If you skip these steps, the installation will fail, but you can re-run ghost setup linux-user systemd.

Ghost Install Explained

You will be prompted for the following pieces of information:

Enter your blog Url:

This is the url your blog will be available at and must include the protocol. e.g http://myblog.com for HTTP or https://myblog.com for HTTPS.

Enter your MySQL hostname:

This determines where your MySQL database can be accessed from. For the most cases the user installs MySQL on the same server, in this case use localhost.

Enter your MySQL username:

Enter your MySQL user name. This is either root or if you have created a custom MySQL user already, you can use this one.

Enter your MySQL password: [hidden]

The password for your MySQL user.

Ghost database name:

Here you have to enter the name of your database server. If you install multiple instances of ghost on your server you need to specify a different database for each instance. If the database you entered does not exist already it will be created for you.

Do you wish to set up a ghost MySQL user?

We recommend setting up a separate ghost user in MySQL that can only access/edit your Ghost database. Ghost-CLI takes care of this for you if you accept.

Do you wish to set up a Ghost system user?

Please answer with Yes, otherwise the CLI won't be able to start your Ghost blog. We create an Ubuntu user with limited permissions necessary to upload images/themes etc only for your ghost instance. If you prompt with No and your installation fails, you can always re-run ghost setup linux-user.

Do you wish to set up nginx?

Sets NGINX up for your blog enabling it to be viewed by the outside world. You can optionally set this up yourself.

Do you wish to set up ssl?

If you do not already have a valid ssl certificate installed for your blog and wish to use secure protocol, Ghost-CLI can take of this for you using the Let's Encrypt certification service. Otherwise you have to setup ssl by your own.

Enter your email (used for SSL certificate generation)

This is required for SSL certification so that you can be kept informed if there is any issue with your certificate such as requiring renewal.

Do you wish to set up automatic ssl renewal?

SSL certificates last 90 days but should be renewed at least once every 60 days. Accepting this means Ghost-CLI will automatically attempt certification renewal.

Note

Usually cron will email you if the job failed or logs will be send to /var/log/messages.

Do you wish to set up systemd?

Please answer with "Yes", otherwise the installation could fail. See difference between systemd and local process manager.

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.

Install & Setup (production)

How to install Ghost on your production server