How to self hosted Ghost in your cloud server

Written on 14 June 2015

After a time in love with Markdown, I choose Ghost to publish my blog post about what I have learned Tech Note. This is a note for: How I Install Ghost in Digital Ocean VPS cloud server. This is not fastest way but good. If you just want to use Ghost just go to ghost.org and register an account.

First, I read some tutorial and do step by step but fail.
After that, I know what I should do to self host Ghost , that is:

  • Install Nodejs
  • Install Ghost.
  • Install Nginx or Apache
  • Install mysql or mariadb (optional)

My Cloud server is Ubuntu1 , It good. I suggested you should to use Ubuntu.

Install Nodejs

Download script to auto download install Nodejs

$ wget https://raw.githubusercontent.com/taaem/nodejs-linux-installer/master/node-install.sh
$ sudo chmod +x node-install.sh
$ sudo ./node-install.sh

After that check version of node and npm

$ node -v

$ npm -v

Now install Ghost

Download latest Ghost version and extract to /var/www/ghost

wget https://ghost.org/zip/ghost-latest.zip  
unzip -uo ghost.zip -d /var/www/ghost  

Install Ghost module

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

First run

npm start --production  

If all thing work, now go to http://:2368 , you will to setup your first user account for Ghost blog.
You can write your own blog post, at http://<your-ip-address>:2368/ghost . But we have some work to do for run solid ghost on cloud. Let's go !

Install Nginx

Install Nginx to server the world, and you blog can work when type http://myblog.com

$ sudo apt-get install nginx

Create a virtual host

$ vim /etc/nginx/sites-available/ghost.conf

Copy these line

server {  
listen 80;  
server_name myblog.com;

location / {  
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_pass         http://127.0.0.1:2368;
}
}

Press i then Ctrl + Shift + V and Esc, final press ZZ
Test virtual host :
cat /etc/nginx/sites-available/ghost.conf If it same with what you copy , you have did right.

Now , keep going !

sudo ln -s /etc/nginx/sites-available/ghost.conf /etc/nginx/sites-enabled/ghost.conf  

Restart nginx to reload your config:

sudo service nginx reload  

Finaly, matching Nginx with ghost by config.js

vim /var/www/ghost/config.js  

Change your domain name

production: {  
        url: 'http://myblog.com',
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },

Almost done, Now making Ghost run forever

cd /etc/init.d/

wget https://raw.githubusercontent.com/TryGhost/Ghost-Config/master/init.d/ghost

sudo useradd -r ghost -U  
sudo chown -R ghost:ghost /path/to/ghost  
sudo chmod 755 /etc/init.d/ghost  

Then vim /etc/init.d/ghost to edit
DAEMON=/usr/bin/node
to
DAEMON=/usr/local/bin/node

Then final command is:

sudo service ghost start  
$ sudo update-rc.d ghost defaults
$ sudo update-rc.d ghost enable

Now go to http://myblog.com to start your first blog post.
If no thing work , some configure may not right, you must correct it. Or send a message to me @Epety

  1. You can register for DigitalOcean account here to run Ghost https://www.digitalocean.com/?refcode=0492a615037c ↩

Read more on Tech Note Ghost