Setting up

In this blog post I describe the steps needed to set up this static blog on a DigitalOcean VPS. I spent a lot of time troubleshooting before I got it to work, so I decided to document the entire process, since I am likely to forget a lot of these small steps. The end result is that I can write blog posts locally in Markdown, push the changes, and then the VPS builds the site.

I had previously set up a website on a VPS hosted at DigitalOcean. I created a droplet there and installed a basic LAMP stack on the DigitalOcean VPS, using this tutorial.

On my local machine

I installed Ruby, along with Octopress, which is a superset (as far as I can tell!) of Jekyll, for quickly generating a skeleton site and hosting a blog.

gem install octopress --pre
curl -L | bash -s stable --ruby=2.0.0
source /Users/vegard/.rvm/scripts/rvm
gem install jekyll bundler
git clone ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
rbenv rehash

To create a new skeleton directory, do

octopress new blog
cd blog
jekyll serve

A basic site is now browsable at localhost. To be able to use this as site/blog, I had to change baseurl to /blog in _config.yml.

Create a git repository in this directory.

git init
git add .
git commit -m "Initial commit"

On DigitalOcean

This tutorial gives steps for deploying a Jekyll blog, through Git, to DigitalOcean. However, simply doing these steps was not quite enough to get it to work. So here I will repeat these steps, but with all of the additional steps I needed to get it to work.

Install Ruby and Jekyll (+ bundler) on the VPS.

curl -L | bash -s stable --ruby=2.0.0
gem install jekyll bundler

Then create a Git repo in the home directory.

cd ~/
mkdir repos
cd repos
mkdir blog.git
cd blog.git
git init --bare

The --bare creates some additional stuff, which we need to set up a post-receive hook.

cd hooks
touch post-receive
nano post-receive

Inside post-receive, put

#!/bin/bash -l

jekyll build --source $TMP_GIT_CLONE --destination $PUBLIC_WWW

Save the file and make it executable by doing chmod +x post-receive.

Then make sure repos is owned by your user (vegard in my case), not root. I had to do the steps above using superuser privileges, so I just changed the ownership afterwards, like so:

sudo chown -R vegard:vegard ~/repos

Back on the local machine, do

git remote add droplet

In my case, I have set up an SSH key, so I did server instead of Then do git push droplet master. Now I can edit my blog locally, and when I’m satisfied, push the changes and they become visible here (remotely).

To add it to a GitHub repository, do

git remote add github

To push to both repositories with git pushall at the same time, create an alias

git config alias.pushall '!git push droplet && git push github'


Afterwards, I decided I didn’t like the standard Octopress layout. So I downloaded a theme called whiteglass, which allows a lot more tinkering, and put that in the blog directory instead. The rest of the process is the same, but on the VPS I had to install some packages for Jekyll:

gem install jekyll-archives jekyll-sitemap jekyll-paginate

Thanks for reading!