This Ghost blog is running on an Ubuntu 14.04 server powered by DigitalOcean. It's a great host and Ghost is gaining some traction with bloggers. DigitalOcean offers a one-click install Ghost image. The version which currently is included in the image is 0.8.0. The latest stable version of Ghost however is v0.11.4. Time to upgrade!
The reason I'm writing this post is that I had a hard time upgrading to the latest version. I constantly got a 502 Bad Gateway after the upgrade and it was driving me nuts. I was missing dependencies and after adding them I got more errors in my
npm and so on...
For those not comfortable editing, moving and navigating your vps in a terminal window the good guys from ghostforbeginners have written a script which will take care of your upgrade. Basically two commands in your terminal and you're done:
SSH into your DigitalOcean droplet:
Run the following command to update Ghost:
sudo wget -O - https://ghostforbeginners.com/updateghost-digitalocean | sudo bash
Ok, maybe I lied a bit. For those on a $5 instance at DO you still will get a 502 Bad Gateway. To fix this you will need to add a swap file. Adding a swap file is super easy:
Adding a swap file
The quicker way of getting the same file is by using the
fallocate program. This command creates a file of a preallocated size instantly, without actually having to write dummy contents.
We can create a 4 Gigabyte file by typing:
sudo fallocate -l 4G /swapfile
The prompt will be returned to you almost immediately. We can verify that the correct amount of space was reserved by typing:
ls -lh /swapfile
-rw-r--r-- 1 root root 4.0G Apr 28 17:19 /swapfile
As you can see, our file is created with the correct amount of space set aside.
Enabling the Swap File
Right now, our file is created, but our system does not know that this is supposed to be used for swap. We need to tell our system to format this file as swap and then enable it.
Before we do that though, we need to adjust the permissions on our file so that it isn't readable by anyone besides root. Allowing other users to read or write to this file would be a huge security risk. We can lock down the permissions by typing:
sudo chmod 600 /swapfile
Verify that the file has the correct permissions by typing:
ls -lh /swapfile
-rw------- 1 root root 4.0G Apr 28 17:19 /swapfile
As you can see, only the columns for the root user have the read and write flags enabled.
Now that our file is more secure, we can tell our system to set up the swap space by typing:
sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=e2f1e9cf-c0a9-4ed4-b8ab-714b8a7d6944
Our file is now ready to be used as a swap space. We can enable this by typing:
sudo swapon /swapfile
We can verify that the procedure was successful by checking whether our system reports swap space now:
sudo swapon -s
Filename Type Size Used Priority
/swapfile file 4194300 0 -1
We have a new swap file here. We can use the free utility again to corroborate our findings:
Our swap has been set up successfully and our operating system will begin to use it as necessary.