Introduction

This article is about "How to create a Ghost-powered blog on Cloud, e.g. DigitalOcean, Vultr, EC2, ... or any (Ubuntu) server.

Pre-requirement

  • An instance of VPS (or dedicated server). You can create one at DigitalOcean, Vultr, Amazon EC2, Google Cloud,...
  • VPS OS: Ubuntu 12.04 or upper (at time of writing this article, I use Ubuntu 14.04)
  • Basic knowledge of Linux commands

Setup

Step 1 - Download

Goto https://ghost.org/download/ and get link download of the latest version of Ghost

Download ghost

mkdir /home/ghost
cd /home/ghost
wget https://ghost.org/zip/ghost-0.7.2.zip

Unzip ghost

sudo apt-get install unzip
unzip ghost-*.zip

Step 2 - Configure your blog

Create config file from example

cp config.example.js config.js
nano config.js

Configure your blog setting, edit production setting including url, server port, mail

production: {
        url: 'https://YOUR_DOMAIN_NAME',
        mail: {
            transport: 'SMTP',
            options: {
                service: 'Mailgun',
                auth: {
                    user: 'XXXXXXXXXXXXXXXXXXXXXXXXX',
                    pass: 'YYYYYYYYYYYYYYYYYYYYYYYYY'
                }
            }
        },
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },

        server: {
            host: '127.0.0.1',
            port: '2368'
        }

For email setting, you can use Mailgun (free) as a mail service for your blog. Remember your port: 2368 as we will need it later.

Step 3 - Install NodeJS and all dependencies for Ghost

Execute the following to add a PPA with Node.js, and confirm by pressing Enter:

add-apt-repository ppa:chris-lea/node.js

Install NodeJS

apt-get update
apt-get install nodejs

Install all dependencies for Ghost blog

cd /home/ghost/
npm install --production

Step 4 - Install and config nginx

Install nginx

sudo apt-get install nginx

Create configuration file for your blog at /etc/nginx/sites-available/ghost-blog

server {
    listen 80;
    server_name YOUR_DOMAIN_NAME;

    location / {
        proxy_pass http://127.0.0.1:2368;
        proxy_http_version 1.1;
    }
}

Link it to sites-enabled so nginx will load this configuration and reload nginx

ln -s /etc/nginx/sites-available/ghost-blog /etc/nginx/sites-enabled/ghost-blog
nginx -s reload

Step 5 - Configuring Upstart

Upstart will automatically start the app on boot and restart Ghost in case it dies. You can read more about creating Upstart service files in this tutorial.

Create the file /etc/init/ghost.conf:

# upstart service file at /etc/init/ghost.conf
description "Ghost Blog"
author "Tober Nguyen <[email protected]>"

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on shutdown

# Automatically restart process if crashed
respawn
respawn limit 10 5

# drop root proviliges and switch to ghost user
setuid ghost
setgid ghost

script
    export NODE_ENV=production
    exec node /home/ghost/index.js >> /home/ghost/access.log
end script

Step 6 - Showtime

Start your Ghost blog

start ghost

Voila! Goto http://YOUR_DOMAIN/ghost to setup admin account and start using Ghost.

References: