Sunday, April 27, 2014

Hosting sites for free on Github

In this blog I would like to explore how we can make use of GIT Pages to host websites for free, and not just hosting, GIT also makes it easy to manage your pages using CMS Lite tool.

Our software stack will be as follows

Github Pages hosting CMS lite tool to edit pages
Google Analytics
Disqus for blog post comments
At a minimum you need to buy a domain name if would like to avoid accessing your site with git pages url, else you can access the site using
Prerequisite (Optional)

I have decided to manage my blog using Jekyll, but this is not mandatory, you may create a basic html site and host it on GIT. Github internally uses Jekyll engine and hence you have the luxury to code the page in Jekyll as well.

Since in this example we will explore building a blog and Jekyll makes it very easy to build a blog aware site
First install ruby and jekyll

Install rubygems followed by jekyll, on ubuntu I had to run following commands

sudo yum install ruby rubygems
sudo gem install jekyll
root@search:/home/search/git# git clone

It is a good idea to begin with a template, I decided to make use of jekyll-bootstrap-3 which is a bootstrap 3 clone of Jekyll bootstrap
I got following error while installing jekyll as sudo account, so make sure you install jekyll as root.

ERROR:  While executing gem ... (Errno::EACCES) Permission denied - /var/lib/gems

Prepare your system to host jekyll powered blogger locally

$ mkdir jekyll_workspace
$ cd jekyll_workspace/
~/jekyll_workHost your site / blog on the internet
space/ $sudo gem install jekyll jekyll-import

-- This will take a while before importing all the libraries

~/jekyll_workspace $ jekyll new gblog

Migrating the existing Blog

First we need to install the jekyll-import gem module as follows

gem install jekyll-import

You can read more about this module here

Blogger provides an option to export entire blog as Atom feed, but unfortunately there is no
jekyll importer as of this writing to import an ATOM feed.

Export the blog as RSS feed
Replace name with your blog name and RECORDS with the number of posts you would like to export.
E.g. I used this to export my blog and upto 500 posts, there isn't a nice way to export all so you will
have to count all the posts before exporting all records.

curl -o gdata.xml

ruby -rubygems -e 'require "jekyll-import";{"source" => "gdata.xml"})'
Start the server and access localhost:4000 to visit the new jekyll powered blog.

~/jekyll_workspace/gblog $ jekyll serve
Configuration file: /home/hari/jekyll_workspace/gblog/_config.yml
            Source: /home/hari/jekyll_workspace/gblog
       Destination: /home/hari/jekyll_workspace/gblog/_site
      Generating... done.
    Server address:
  Server running... press ctrl-c to stop.

Host your site / blog on the internet

Github pages support Jekyll websites, so it should be easy for us to now
publish the locally created blog site to github so the entire world can access your new site

Create a new project respository on github with following naming convention

where <USERNAME> is your github name.