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

Overview

This the official guide for self-hosting Ghost using our recommended stack of Ubuntu 16.04 or 18.04. If you're comfortable installing, maintaining and updating your own software, this is the place for you. By the end of this guide you'll have a fully configured Ghost install running in production using MySQL.

This install is not suitable for local use or contributing to core.

Save time with our DigitalOcean One-Click Application

This is a detailed manual install guide, but we've also teamed up with our friends over at DigitalOcean to automate nearly the entire process and have you up and running in just a few minutes 👉


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 update

# Update installed packages
sudo apt-get 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 nginx

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

sudo ufw allow 'Nginx Full'

Install MySQL

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

# Install MySQL
sudo apt-get install 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
quit

# 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 8
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash

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

Install MongoDB

# 切换到下载目录
cd Downloads

# 下载
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz

# 解压
tar -zxvf mongodb-linux-x86_64-3.0.6.tgz

# 将解压包拷贝到指定目录
mv  mongodb-linux-x86_64-3.0.6/ /usr/local/mongodb

# MongoDB 的可执行文件位于 bin 目录下,所以可以将其添加到 PATH 路径中
export PATH=/usr/local/mongodb/bin:$PATH

# 创建数据库目录
# /data/db 是 MongoDB 默认的数据库路径
# 这个目录在安装过程不会自动创建
mkdir -p /data/db

# 启动 MongoDB 服务
# 如果你的数据库目录不是/data/db,可以通过 --dbpath 来指定。
sudo /usr/local/mongodb/bin/mongod

# MongoDB 后台管理 Shell
# 保证 MongoDB 服务已经启动着
sudo /usr/local/mongodb/bin/mongo