Setting up Ghost Blog on Ubuntu

Setting up Ghost blogging platform on Ubuntu

Blogging has been a great way to express your opinions, share information and publish findings in the internet. One of the oldest and most widely used software is wordpress.

But wordpress is filled with too many features which can be overwhelming for users who just want to write. There have been quite a few CMS (Content management softwares) which have tried to recreate what wordpress had done.

One of the newest entrant to the blogging software scene is Ghost. It is a very lightweight and also fast blogging platform which focusses on just enough features to get the users started on writing articles rather than combing through a list of features they have to know before they can even put a word out.

As they have quoted on their main website,

Ghost is an an editor for writers

In this article we will be looking at how to set up your first ghost blog on a ubuntu machine. I have used aws as my hosting service. I will also write another article on how to setup a free server on aws (for a year).

Lets get Started!

Firstly, You would have to ssh into your aws instance.
When you set up your EC2 instance on AWS, you will be given a key file (usually in .pem format) which will be the mode of authentication to login into your server.

    $ssh -i ./path-to-your-key ubuntu@your-elastic-ip

you will be using the ssh command with the path to your ec2 key and username@ip-address to ssh into your server.

Once you successfully login your server, You can get started on setting up the prerequisites for your ghost blog.

  1. nvm (Node version Manager).

Since, Ghost is build on top of nodeJS, we would have to install the nodeJS and npm. Instead we will be installing nvm which will take care of the installing & versioning of nodeJS. At this time of writing, The maximum supported version of nodeJS that is required by Ghost id 6.9.1. If you install the latest nodeJS which is currently 7.X or 6.10.X LTS, you will not be able to set up ghost

//grab the lastest version of nvm install script and run it
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

To install the supported version of nodeJS use :

nvm install 6.9.1 //you can enter any valid version number
nvm use 6.9.1

Now nodeJS & npm is all set to go!

  1. Nginx

Nginx is a web server which can double up as a reverse proxy/ Load balancer, which you can use to listen on the 80 port and redirect the traffic internally to the port on which ghost is running on (usually 2368). Apart from that, If you have some good knowledge of how backend system work, you can also set up nginx to directly serve all your HTML, CSS, JS and data files which will be much faster and more performant than letting nodeJS handle it.

apt-get install nginx

This should grab the latest copy in the repo and install it. Then we should set up the nginx configuration.

open up the conf in a editor like vi / nano
sudo vi /etc/nginx/nginx.conf

It will look like the following :

    server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost;

    location / {
        try_files $uri $uri/ =404;
    }
}

press i to get into edit mode on vi editor & goto the location / block & remove the lines there and paste the following lines :

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:2368;
        proxy_redirect off;
  1. Last but not the least - Ghost tar ball

This basically contains all the ghost code in a tar or a zip format which you would have to download and unzip in your server to use.
download & unzip the ghost tarball using :

sudo wget https://ghost.org/zip/ghost-latest.zip
sudo unzip -d ghost ghost-latest.zip
4. cd into your ghost directory & install all the dependencies :
cd ghost
npm install --production
  1. Install pm2 to cluster our ghost blog & keep it running forever. Usually nodeJS app should be used in cluster mode in production environments to ensure that all the processor cores of our server is used up. Another reason for using PM2 is to keep the app running at start up (Imagine your server goes down for some reason, as soon as it is up pm2 will make sure that out ghost blog is also up and running)
npm install -g pm2
pm2 start index.js -i 2 --name ghost //2 is the number of cores you want your ghost blog to run on

Now, If you have already mapped a domain to your server ipaddress then you can enter your domain in the browser / enter your public IP assigned by amazon & you should be able to reach your blog :-)

Bala Abhinav

I am a passionate coder, full stack dev and software architect based out of Chennai, India. I love writing about full stack javascript development, automation and building scalable backend systems.

Chennai, Tamil Nadu, India