How to Install and Configure a Ghost Blog with Apache and forever in a Debian Jessie DigitalOcean Droplet

Introduction

Ghost is a simple yet powerful open source blogging platform that runs on JavaScript through the Node.js runtime. In this guide, we will install Ghost, run it with forever and use Apache as a reverse-proxy for production environment.

Prerequisites

In order to complete the steps in this guide, you will need to have the following:

  • A Debian Jessie server: You may want to see this guide in creating your first Debian Jessie droplet in DigitalOcean.
  • A non-root user with sudo privileges: You can set this up by following the Debian 8 initial server setup guide.

Step 1 — Installing Apache

We'll install Apache to use it as a reverse-proxy for our blog.
First, we must first update the apt package index:

sudo apt-get update

To install Apache web server:

sudo apt-get install apache2

Step 2 — Installing Node.js

To run Ghost, we'll need install Node.js, the foundation for our Ghost platform.
First, install some prerequisites:

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

Then install nodejs:

sudo apt-get install nodejs

Finally, we'll install build-essential to compile and install native addons from npm:

sudo apt-get install build-essential

Step 3 — Installing Ghost

First, you will need to pick a path in your file-system where you want to install Ghost.
Assuming you have selected /var/www/, let's change-dir into it:

cd /var/www/
Note: Do not forget to replce /var/www/ to your desired path.

Next, we'll download the latest version of Ghost:

sudo wget https://ghost.org/zip/ghost-latest.zip

To extract the downloaded zip file, we'll install unzip:

sudo apt-get install unzip

Finally, we'll extract the download to a directory named "ghost", remove the downloaded file and cd into the directory:

sudo unzip -d ./ghost/ ghost-latest.zip && rm ghost-latest.zip && cd ghost

Step 4 — Configuring Ghost

Now that Ghost has been installed, we'll need to configure it.
First, install SQLite3 via npm from source:

sudo npm install sqlite3 --build-from-source

Next, we'll integrate it to the Ghost platform:

sudo npm install --production
Note: Please be patient. Installing may take up to 5 minutes.

Then, we'll create and edit the config.js file with nano to suit our set-up

sudo cp config.example.js config.js && nano config.js
Note: Change the "url" directive to your domain or public IP in the "production" code block. Don't include the trailing-slash.
Tip: You may also want to check this doc to configure email settings for your Ghost blog.

If you're done editing the config.js, press crtl+x and y to save your changes.

Finally, to test our set-up, start ghost blog:

sudo npm start --production

You should see something like this:

This set-up should be fine, unless you plan to close your terminal window or end your SSH session. In which case your blog will shut down along with it. To solve this problem, we'll run Ghost with forever.

To stop Ghost blog, press ctrl+c.

Step 5 — Installing forever

To install forever:

sudo npm install -g forever

To start Ghost with forever:

sudo NODE_ENV=production forever start --sourceDir /var/www/ghost index.js

To stop Ghost with forever:

Note: Don't forget to change "/var/www/" to your chosen path.

Step 6 — Configuring Apache as Reverse-proxy for Ghost

To configure Apache as a reverse-proxy for Ghost, refer to the code block below.

Info: We don't need to explicitly declare a "DocumentRoot" because we're going to forward all traffics to the Node.js server anyway.
<VirtualHost *:80>

	ServerName "http://my-ghost-blog.com"

	ProxyPreserveHost On
	ProxyPass / http://127.0.0.1:2368/
	ProxyPassReverse / http://127.0.0.1:2368/
	
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Note: Don't forget to change the ServerName directive to your own domain or public IP.

Conclusion

In this guide, we have shown you how to install and configure Ghost as a blogging platform, how to run it with forever and how to reverse-proxy it with Apache for production use.