Ghost Blog 0.11.3 and upwards on Debian Jessie

Hi again... This time, for the first time, I'm gonna talk about Ghost.
Ghost, is a blog platform, written in NodeJS, that has the aim to provide a light, themeable, featured and yet easy to use blog platform. Unlike Wordpress, which evolved to be a full featured CMS, Ghost sticks to the original objective of being just a blogging platform.

This blogs runs atop Ghost, and, until recently, I never had a single problem running Ghost Blog on my Debian based VM.
Recently, but, since Ghost is preparing its first 1.0 release, with current 0.11 release quickly preparing to become LTS version, 0.11 dropped support for NodeJS 0.10 from 0.11.3.
Since Debian Jessie's packaged Node version is 0.10.29, all of the sudden, my blog got stranded at 0.11.2.

So, I'm going to write down how to go from Debian Jessie's packaged NodeJS/npm to up-to-date Debian repository ones.
Also, I'll show how the process of updating Ghost Blog goes, as I update Ghost from 0.11.2 to latest 0.11.4 (as of the writing of this post)... there we go!

Updating Jessie's ancient packaged node/npm

I've being running Ghost with packaged node/npm. Just a simple apt-get install node npm command lasted to got necessary environment up for almost a year... but with node being at version 6, leaving behind major changes at version 4, packaged 0.10.29 is really old nowadays:

Checking packaged version:

alex@debian:~$ node -v

To ease the update process, provides a shell script.
It will add a repository file under /etc/apt/sources-list.d for your correct Debian version, update your sources and check everything for you... a piece of cake.
So, ensure you have curl command installed (if not, just: apt-get install curl), cd to some administrator home folder and run the following single line command (you should but just download first, check the script for ugly things, and run it afterwards)

curl -sL | sudo -E bash -

After the update process you'll be invited to execute the install, by typing:

apt-get install nodejs

Note: By replacing Jessie's packages by nodesource's ones, lot of Debian related packages will be erased, since they are no longer needed... You may check whether this may cause a conflict in your system if you're running other nodejs apps.

Afterwards we can check that either node and the npm package manager have being dramatically updated:

root@debian:~# node -v

root@debian:/var/www/ghost# npm version
{ npm: '3.10.10',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '56.1',
  modules: '48',
  node: '6.9.4',
  openssl: '1.0.2j',
  uv: '1.9.1',
  v8: '',
  zlib: '1.2.8' }


The Ghost upgrade process...

This is how it all goes. Let's imagine we do have our blog filesystem sitting at /var/www/user/ghost folder. Let's cd into our public root folder and make a backup first!!!!

cd /var/www/user
tar -cvpzf ghost_backup.tar.gz ghost

Now, with a copy in place is time to stop Ghost:

service ghost stop

I'll always ensure it is really dead:

root@debian:/var/www/user# service ghost status
● ghost.service - LSB: Ghost Blogging Platform
   Loaded: loaded (/etc/init.d/ghost)
   Active: inactive (dead)

Jan 02 20:27:41 debian systemd[1]: Starting LSB: Ghost Blogging Platform...
Jan 02 20:27:41 debian ghost[8614]: Starting Ghost: ghost.
Jan 02 20:27:41 debian systemd[1]: Started LSB: Ghost Blogging Platform.
Jan 14 19:42:37 debian systemd[1]: Stopping LSB: Ghost Blogging Platform...
Jan 14 19:42:37 debian ghost[1849]: Stopping Ghost: ghost.
Jan 14 19:42:37 debian systemd[1]: Stopped LSB: Ghost Blogging Platform.

Now it's time to download the new version.

cd /var/www/user/ghost
mkdir update
cd update
curl -L -O

Next step is to replace current files with the new ones:

cp update/*.md update/*.js update/*.json .
rm -R core
cp -R update/core .
cp -R update/content/themes/casper content/themes

Once we got them in place, it is time apply the upgrade, running as root:

npm install --production

After letting npm work for a while, and if no errors arise, we are almost done. Time to clean up of downloaded update files and put permissions back to user ghost runs as:

rm -R update
chown -R user:user ./*

A ls -l look at the /var/www/user/ghost folder should look something like this:

total 296
-rw-r--r--   1 user user   4511 Jan 14 19:48 config.example.js
-rw-r--r--   1 user user   4579 Jun  4  2016 config.js
drwxr-xr-x   6 user user   4096 May 18  2016 content
drwxr-xr-x   5 user user   4096 Jan 14 19:48 core
drwxr-xr-x   2 user user   4096 Dec  6 20:18 downloads
-rw-r--r--   1 user user  31937 Jan 14 19:48 Gruntfile.js
-rw-r--r--   1 user user    725 Jan 14 19:48 index.js
-rw-r--r--   1 user user   1065 May 18  2016 LICENSE
drwxr-xr-x 103 user user   4096 Jan 14 19:49 node_modules
-rw-r--r--   1 user user 211911 Jan 14 19:48 npm-shrinkwrap.json
-rw-r--r--   1 user user   3029 Jan 14 19:48 package.json
-rw-r--r--   1 user user   2942 Jan 14 19:48
-rw-r--r--   1 user user   4710 Jan 14 19:48

So, it's time to restart Ghost Blogging Platform again!

service ghost start

and check it's all fine:

root@debian:/var/www/user# service ghost status
● ghost.service - LSB: Ghost Blogging Platform
   Loaded: loaded (/etc/init.d/ghost)
   Active: active (running) since Sat 2017-01-14 19:50:46 CET; 6s ago
  Process: 3185 ExecStart=/etc/init.d/ghost start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/ghost.service
       └─3191 /usr/bin/node /var/www/user/ghost/index.js

Jan 14 19:50:46 server01 ghost[3185]: Starting Ghost: ghost.
Jan 14 19:50:46 server01 systemd[1]: Started LSB: Ghost Blogging Platform.

That's it!!!

In the event of trouble...

Since I faced the problem of an upgrade failure as I tried to upgrade to 0.11.3 before switching to updated node version, here is how simple is to go backwards: just restore your backup and restart it again:

cd /var/www/user
mv ghost ghost.broken
tar -xfv ./ghost_backup.tar.gz
rm -rf ghost.broken
service ghost restart

So... happy blogging!!!

comments powered by Disqus