Introduction:

Having run a web server for many years to host some general websites for university projects etc. I have always used some kind of hosting control panel from cPanel to zPanel and finally, I have stayed with Vesta CP for a while. Vesta CP is running well and I have not had any problems so far... Until trying to get Ghost Blog to function properly as its node.js based.

Ghost Blog

I was originally introduced to Ghost Blog through a colleague David, he blogs about useful things that could come in handy again some day down the line. Having worked with Wordpress loving all the features the come with it, the simplicity of Ghost looked very attractive, making me want to test it out for myself.

Installation

My web server is an EC2 instance running on AWS (Amazon Web Services) with a static IP address. For this installation guide, I'm going to create a Ghost Blog with the domain travel.alexgittings.co.uk. I'm presuming that the domain is already forwarding to the web server IP address.

Vesta CP Preparation

Load up your Vesta control panel and add a new web domain. When creating this domain do not use "Proxy Support" as we will be adding NGINX information manually. The record should look like this:

Getting Dirty on the CLI!

Once you have created the domain in Vesta CP you will now have a folder on your web server where all the files will be located for this domain. Mine for examble is /home/admin/web/travel.alexgittings.co.uk/public_html

Installing Prerequisites

For Ghost to run we need to install node.js we can do this with these commands.

sudo apt-get update
sudo apt-get install nodejs

We will also need the node package manager we can do this with this command

sudo apt-get install npm

This is all we need for node.js

Setting up Ghost

By now if you navigate to your domain you will see a landing page that Vesta places in your folder. We first need to navigate the cli and bring our working directory to our public_html folder for our domain.

cd /home/admin/web/travel.alexgittings.co.uk

Vesta CP will create an index page we can remove this.

rm index.html

Now to the good stuff downloading and installing Ghost.

curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
unzip -uo ghost.zip

Now we have downloaded the files and unzipped them we need to edit the config file

nano config.example.js

and change these lines to your domain and your Vesta CP Internal IP address your internal IP address can be found under the IP tab at the top of Vesta CP. I will also be changing the port as I have multiple Ghost blogs running but you don't need to do this.

  • my-ghost-blog.com
  • 127.0.0.1

Below is my configuration

config = {
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
   url: 'http://travel.alexgittings.co.uk',
   mail: {},
   database: {
       client: 'sqlite3',
       connection: {
           filename: path.join(__dirname, '/content/data/ghost.db')
       },
        debug: false
    },

    server: {
        host: '172.31.25.222',
        port: '3000'
    }
},

Save the file and now we can rename it to config.js

mv config.example.js config.js

We can now install the blog

npm install --production

and run the blog finally!!

npm start --production 

WRONG!!

Navigating to travel.alexgittings.co.uk:3000 does not work as vesta panel needs to know via NGINX where to redirect for this we need to add some NGINX configuration.

Navigate to your conf directory mine is /home/admin/conf/web/nginx.conf once we are in this we need to add some code to redirect the web request. Swap out the IP addresses with your IP addresses and port numbers, change the server name and root directory.

server {
    listen 172.31.25.222:80;

    server_name travel.alexgittings.co.uk;

    root /home/admin/web/travel.alexgittings.co.uk/public_html;
    index index.js;

    location / {
        proxy_pass http://172.31.25.222:3000;
    }
}

restart nginx

/etc/init.d/nginx restart 

start the ghost

npm start --production 

Once we start the service again and navigate to travel.alexgittings.co.uk you should be welcomed by Ghost.

Advanced

I wanted to tweak some things so I can start and stop blogs easy and have the blogs start on server reboot.

Start and stop ghost easily

We can add a little code to be able to start and stop the ghost service very easily

cd /etc/init/
touch ghost_travel.conf
nano ghost_travel.conf

and use this script

description "ghost server"

start on started mountall
stop on shutdown

respawn limit 99 5

script
export HOME="/home/admin/web/travel.alexgittings.co.uk/public_html"
cd $HOME
exec npm start --production >> /var/log/ghost.log 2>&1
end script

post-start script
end script

changing the directory and saving will allow you to use these commands

start ghost_travel
stop ghost_travel
restart ghost_travel

making it easier to manage multiple blogs.