Dummy guide to Ghost installation on Ubuntu

When installing Ghost manually on a VPS or your home machine, you will have to handle everything from installing nodeJS to configuring Nginx. This is a straight forward guide for installing and configuring ghost.

We will

  1. install node.JS (ghost is built on node.js)
  2. setup Ghost
  3. setup pm2 (run ghost forever)
  4. setup nginx (proxy requests from port 80 to 2368)

Install node.JS

Let's start by updating apt-get

sudo apt-get update

After it is done install some dependencies before installing node.js

sudo apt-get install python-software-properties python g++ make
sudo apt-get install -y build-essential openssl libssl-dev pkg-config

Next, install nodejs

sudo apt-get install nodejs

Now here is the point where I started losing my sanity. Scripts that use node (like pm2 and ghost) will not work with nodejs as the reference is not included!

I finally managed to resolve it by running this

sudo ln -s `which nodejs` /usr/local/bin/node

Now run

npm update

and you are ready to install ghost!


Setup Ghost

Start by downloading the latest ghost version in your home directory

cd ~
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip

After it is done make sure you have installed unzip, if not run

sudo apt-get install unzip

Then let's unzip ghost

sudo mkdir /var/www/
sudo unzip -uo ghost.zip -d /var/www/ghost

Now let's install

cd /var/www/ghost && npm install --production

Now let's make some final configurations

sudo vi config.js

and change host: '127.0.0.1' to host: '0.0.0.0' then save and exit.

Next, create a ghost user

sudo adduser --shell /bin/bash --gecos 'Ghost application' ghost
sudo chown -R ghost:ghost /var/www/ghost/

Then use it

su - ghost
cd /var/www/ghost/

You should now be able to run it

npm start --production

go to <your blog URL>:2368 you should see ghost up and running. Make sure you don't close it until you've checked that it is already working.


Setup pm2

NB: make sure that you are using the ghost user we've created in the previous section.

cd /var/www/ghost/
sudo npm install -g pm2
echo "export NODE_ENV=production" >> ~/.profile
source ~/.profile
pm2 kill
pm2 start index.js --name ghost
pm2 dump
sudo pm2 startup ubuntu

So right now you can check your blog on <your blog URL>:2368 without needing to keep your terminal busy.


Setup Nginx

This is the final step.

Remember to exit the ghost user we were using in the previous section before starting this one.

Let's start by installing Nginx using apt-get

sudo apt-get install nginx
cd /etc/nginx/

Remove default added configurations

rm sites-enabled/default

Let's start adding your ghost configuration

cd sites-available
touch <your blog URL>

Now let's add this to the file we've created

server {
    listen 0.0.0.0:80;
    server_name <your blog URL>;
    access_log /var/log/nginx/<your blog URL>.log;

location / {
    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;
    }
}

symlink that to sites-enabled

cd ..
ln -s sites-available/<your blog URL> sites-enabled/<your blog URL>

Now let's put these changes into action

sudo service nginx restart

You should have your blog up and running by now!


References