This site uses Jekyll, a simple, blog-aware, static site generator written in Ruby. I use the very inexpensive hosting provideder, NearlyFreeSpeech.NET. Prior to switching over to Jekyll my site was just a few static HTML pages, serving as a portfolio to the various games I’ve made over the years. However, I want to start writing more, and decided to have Jekyll power my site. If you’re looking for a similar setup hosted on NearlyFreeSpeech.NET then this post is for you!
About this Site
- This site is built using Jekyll.
- This site is hosted on NearlyFreeSpeech.NET.
- This site uses a variation of the popular Pixyll theme.
- This site is source-controlled via a private repository on GitHub.
Why I use NearlyFreeSpeech.NET (NFSN)
NFSN is a pay-as-you-go DIY web hosting provider. They offer everything I need to run a site such as this one, and each site I maintain with them costs me just a few dollars per month. Yes, you could host your own Jekyll site via GitHub pages, but I prefer the freedom I get hosting with NFSN.
Using GitHub for Source Control
I am not going to give a tutorial on git, or GitHub. If you need to learn the basics please read GitHub’s introductory guide. I host this site in a private repository on GitHub. Whether you use GitHub, GitLab, or BitBucket, I suggest hosting your own site in a git repo as well. Such a setup allows you to easily fetch updates via the command line from your NFSN server.
Setting Your Site Up
So you created a new account with NFSN, registered a new domain, and have your Jekyll site ready to publish. What’s next? First, you need to SSH into your new server:
ssh YourNfsnUserName_YourNfsnSiteName@ssh.phx.nearlyfreespeech.net. If you don’t want to enter your password everytime you SSH into your server then read this guide for setting up your own SSH key.
After you SSH into your server run the following command:
cd /home. Now, if you do an
ls from here you will see a few directories, as described from NFSN’s documentation:
public: This directory is the heart of your site. All of the content in this directory is directly accessible via the web. You can put all your static HTML files, images, .htaccess files, and most scripts in this directory.
protected: This directory is available for data files and other content that should be indirectly accessible via the web. For example, putting included source files, libraries, configuration and permanent data files that are used by PHP or CGI scripts into this directory makes them accessible to the script, but prevents them from being directly downloaded over the web.
private: This directory is yours to use for personal files that you do not want accessible via the web at all. For example, if you’re building a custom C++ CGI script, it would be appropriate to put the source code in this directory. This directory is also your “home” directory for Unix shell purposes.
You are going to clone your site’s git repository into the
/home/private directory. This is accomplished via the following steps, assuming GitHub is where your repo is hosted:
cd /home/private git clone https://github.com/YOUR_USER_NAME/YOUR_SITE_REPO.com.git
The contents of your git repository should now be in your
/home/private directory. Next, you need to do some setup for Ruby which will allow you to build and deploy your site.
Configuring Ruby and Building Your Site
Per Jekyll’s documentation, we are using Bundler to track and install the necessary gems needed for your site. You need to configure your NFSN server properly, and tell it where to install all of your gems. To accomplish this you must add a couple of enviroment variables to your
.bashrc file. If you don’t already have a
.bashrc file then do the following while SSH’ed into your NFSN server:
cd ~ vim .bashrc
From here, you should have your
.bashrc file open in vim. I will not go into the details on how to use vim, but add the following two lines to your
.bashrc file, and be sure to save and exit the file:
export RB_USER_INSTALL='true' export GEM_HOME=/home/protected/gems
Now, you need to make a directory to install all of your gems, and install Bundler:
cd /home/protected mkdir gems gem install bundler
Currently, you have a directory in
/home/private containing your site’s git repo, a directory in
/home/protected for installing gems, and added a couple of enviroment variables needed for building your site. All that is left is building your site to your
Hop back to your site’s git repo:
From here, assuming everything above went well, do the following:
bundle install bundle exec jekyll build --destination /home/public
You should now find the generated content of your site in
/home/public and your site should be fully accessible via your favorite web browser. If you need to setup HTTPS, NFSN makes this very easy. Just run the following command from your
These are the exact steps I followed to setup Jekyll for my site, as you see here. I had some help from this blog post, but put my own spin on things a bit, and wanted to document my process for my own future reference. We could expand on our setup a bit, such as writing a bash script to reduce the number of steps necessary to SSH into our NFSN server and pull in new changes to our site. However, what I have going now works good enough for me. If you made it this far, and setup your own blog, send me a link to your site!