Installing Sinatra on WebFaction

WebFaction is a great host, but because its offerings are so diverse, installation can be a hassle for certain applications.

Most recently, I wanted to get Sinatra up and running, but the default install comes with a host of problems, and the WebFaction blog post about installing Sinatra has a few errors.

Below, I’ll lead you through the installation process step by step to alleviate any potential headaches.

First, in your WebFaction control panel, install a Passenger app, which in my case (and this is probably important) was version 3.0.11, with nginx 1.0.10 and Ruby 1.9.3. Name it whatever, of course, but for the sake of this post, I’ll be referring to it as passenger_test. Also, attach it to some domain or sub. Now go grab a glass of water, because Ruby installs take a while.

Once it’s done, ssh into your account and go to the project folder. Create the GEM_HOME variable for installing Sinatra and, for the sake of ease, put the bin folder on the PATH. Also, we can take this time to remove the default project “hello_world”.

$ export GEM_HOME=$PWD/gems
$ export PATH=$PWD/bin:$PATH

$ gem install sinatra
$ rm -rf hello_world/

Now we’ll create our own project.

$ mkdir myapp && cd myapp/
$ touch config.ru myapp.rb
$ mkdir public/ tmp/

Simple config.ru and myapp.rb files are written below, with notes:

2: The dot and slash are necessary because the current directory is not on $LOAD_PATH ($: for short if you ever need to append something to it)
3: This line is written as Sinatra.application in the WebFaction blog post, which will not work because application is not a method. Also notice the capitalization.

Finally, point nginx to your new app instead of the old by editing the root line in ~/webapps/passenger_test/nginx/conf/nginx.conf as follows:

/home/[your username]/webapps/passenger_test/hello_world/public;

becomes

/home/[your username]/webapps/passenger_test/myapp/public;

Now restart nginx (by simply typing restart in the terminal), and visit your page. It should be there.

I encountered a couple additional errors along the way during my first install, errors that are not happening to me on subsequent installs. I think the WebFaction team has responded already (lightning fast!) to my reporting. But I’ll still detail some fixes that may help you if you run into more trouble:

  1. In the ‘start’ script located in ~/webapps/passenger_test/bin, there are two variables called TMPDIR and PASSENGER_TMPDIR. These were causing problems for me before, and actually by the recommendation of WebFaction support, simply removing these from the script helped.
  2. Tilt was throwing an invalid gem spec error for the date format in its specification file. If this happens, go into project_root/gems/specifications/tilt-1.3.3.gemspec and changed the s.date = %q{2011-08-2500:00:00.000000000Z} line to s.date = “2011-08-2” (or whatever the date is there).

4 Responses to “Installing Sinatra on WebFaction”

  1. Thanks so much for this

  2. Glad to have helped!

  3. Thanks from me too. Just signed up to webfaction and this was exactly what I needed.

  4. hi can you explain this sentence a little bit more “First, in your WebFaction control panel, install a Passenger app, which in my case (and this is probably important) was version 3.0.11, with nginx 1.0.10 and Ruby 1.9.3. “. how inst. into cp ? i try to host my sinatra app into hostmonster but i couldn’t.
    thank you

Leave a Reply