I did a thing! Dreamhost, Ruby 2.1.2, Middleman, Rbenv

My husband needed a website. He’s a actor. It’s a good thing to have. He gave me his design idea a while ago. It was a pretty good idea. I wanted it to be more than just html and css, because it’s prettier, the URLs are prettier, etc. So I started looking at one of the websites for an organization/conference I helped out with because it was simpler than starting a Rails app (plus I only wanted a static site), and I figured I should learn how a more simplistic Rack application worked.

I’ve been using Dreamhost for years, but almost exclusively for WordPress sites or redirecting (i.e. maryloulenhart.com). I felt a little bad that I’m a web developer and I didn’t even have a reasonable website myself. Not that bad though.

Dreamhost only runs Ruby-1.8.7 — it’s pretty far behind. I also had never set up an environment inside my Dreamhost website shell. So I was kinda lost. Thankfully their wiki is pretty great. I found this page first. That doesn’t seem that helpful but the blog post it links to is. He uses Ruby 1.9.3 (which has recently been deprecated) and Sinatra but that’s close enough and he made his instructions abstracted enough to use any old Rack application. Which is awesome.

So after a few weeks of brooding over whether or not I wanted to embark on setting up an environment because uuuugggghhhh I finally had some time and decided I would stop disappointing my husband’s dreams of a website. First of all, my Gemfile looks like this:

source 'https://rubygems.org'

ruby "2.1.2"

gem "middleman", github: "middleman/middleman", branch: "v3-stable"
gem "rack-contrib", "~> 1.1.0"
gem "rack-rewrite", "~> 1.5.0"
gem "puma", "~> 2.8.2"
gem "haml"
gem "rb-inotify"
gem "therubyracer"
gem "fcgi"

# Live-reloading plugin
gem "middleman-livereload", "~> 3.1.0"

# For faster file watcher updates on Windows:
gem "wdm", "~> 0.1.0", :platforms => [:mswin, :mingw]

It didn’t at first, I had to do some typical googling to figure out the right middleman source, and also that in order to get middleman to run correctly, one needs ‘rb-inotify’ and ‘therubyracer’ gems. Also, the comments in the blog post mentioned above is where I discerned the need for ‘fcgi’. The rest were part of my app already.*

As it was already a Rack app, I had a config.ru making use of Rack::Rewrite to make pretty rails-y-esque URLs. You can also set up a redirect to a custom 404 page in this file. I recommend reading up on Middleman and Rack.

The app basically consists of my Gemfile, my config.ru file, my dispatch fcgi files (again, created due to the blog post linked above), and then my source html & sass files. It’s nice and simple. Most of the functionality is in config.ru.

A few caveats that aren’t the best but for now it’ll have to do:
1. As mentioned in Micah Chalmer’s blog post about setting this up, Dreamhost kills the process after a certain amount of time, and then spinning it back up takes like 10 seconds. After that, it browses normally. This is fine for a small, static, personal website. I recommend looking for other resources if that’s not cool. (I may try to do the same at some point. For instance, Heroku. I love Dreamhost but Ruby 1.8.7? Seriously? >.>)
2. I noticed updates take a bit to propagate. It’s set up to use FastCGI but I’ve got my own little bubble of an environment set up. In fact, I didn’t see the update propagate until I left the site alone long enough for the process to be killed and re-load. It doesn’t take too long for that to happen, though, ~10 minutes it seems. For this case that seems okay to me.

Overall though, I’m pretty excited to have his website out there: seanlenhart.com (hire my husband!)


*Note: I still am not really married to haml. I use slim at work but started with haml originally, and while any templating language isn’t perfect, I am starting to warm up to slim.

Leave a Reply

Your email address will not be published. Required fields are marked *