Updating Ghost on Digital Ocean/Ubuntu

Since I'm running a self-hosted version of Ghost I don't have the advantage of auto-updates (like I would if my site were hosted on Ghost.org). In general I like having more control over the install and I've learned a lot about Ghost and nginx in the process but there are times I regret it.

This weekend was one of those times.

How it all started##

Earlier in the week I was reading the Ghost Development Blog and realized my site was running Ghost 0.5.x, far behind the current 0.7.3 release. Included in the updates were many fixes, optimizations and a major UI upgrade.

Excited about the new version I decided to upgrade.

How to upgrade##

Instead of walking you through every error and hiccup I encountered along the way I'm going to explain what eventually worked for me. The process below might help if you tried upgrading and are having any of the following issues:

  • 502 Bad Gateway error after completing the upgraded
  • cannot run in wd error in npm
  • killed error in npm

A few other specifics about my setup:

  • I'm running Ghost with Nginx on Ubuntu (on Digital Ocean)
  • My previous version was 0.5.x, and I upgraded to 0.7.3.

Backup####

Before starting you should definitely backup your site. There is at least one step where a typo could erase all your hard work. The easiest way to download a backup of your content is to login to the admin and go to Settings > Labs, then click the Export button. This will download a json file of your posts, but not your assets.

For backing up assets and themes there are other options beyond the scope of this article.

Download and Upgrade####

First, ssh into your server as root:

ssh root@your-site.com

Before starting the upgrade you should stop the Ghost service:

service ghost stop

Now install the build-essential package:

apt-get update
apt-get install build-essential

Change the working directory to your web root. In my case /var/www:

cd /var/www

Get the latest Ghost release:

wget http://ghost.org/zip/ghost-latest.zip

These next steps are critical and is what caused a good deal of issues for me. First we're going to remove the Ghost core files, then extract the files for the new release. The -uo flag tells unzip to extract newer versions of files and create new files where necessary. If you leave this out you'll be in a world of hurt.

rm -rf ghost/core
unzip -uo ghost-latest.zip -d ghost

Set the permissions on the files so the ghost process has control:

chown -R ghost:ghost ghost/*

This next step might not be necessary in most cases, but it's something I did while trying to get things working. I cleaned my npm cache, removed all node_modules and reinstalled them.

cd ghost
npm cache clean
rm -rf node_modules
npm install --production

Go have a cold one, this could take a few minutes...

killed?

If during this process you see a killed response in npm you're probably running out of memory. On Digital Ocean you can increase your swap space following these instructions. After increasing the swap space rerun:

npm install --production

Now restart Ghost and Nginx:

service ghost start
service nginx restart

At this point you should be able be able to login to your site and see the updated admin to verify you're running the newest version.

Hopefully this saves others some headaches so you can continue to enjoy Ghost.

Comments