Subscribe to the MPC blog rss feed feed-icon-14x14
 

Getting a Sinatra App Running with Passenger



Posted on 05:35AM on 08/07/2008
Tags: sinatra, passenger, blog

So, I finally managed to get this site running properly. It's now using Apache and Passenger to serve. It's quite easy to get Apache and Passenger setup. Just google it and follow the instructions. More difficult, however, is the setting up of the rackup file since Sinatra runs under Rack. For posterity, here is my working config.ru for this site (with sensitve stuff changed):

 #I keep Sinatra in a vendor folder under the app root - like Rails
  vendor_path = File.expand_path(File.join(File.dirname(__FILE__), "vendor", "sinatra", "lib"))
local_path = File.expand_path(File.dirname(__FILE__))
$:.unshift(local_path) unless $:.include?(local_path)
$:.unshift(vendor_path) unless $:.include?(vendor_path)

require 'rubygems'
require 'sinatra'

Sinatra::Application.default_options.merge!(
  :run => false,
  :env => :production,
  :raise_errors => true,
  :sessions => true,
  :app_file => '/home/public_html/app/the_app.rb',
  :root => "/home/public_html/app",
  :views => "/home/public_html/app//views"
)

log = File.new("sinatra.log", "a")
STDOUT.reopen(log)
STDERR.reopen(log)

require '/home/public_html/app/the_app'
run Sinatra.application

This also allows for logging and enables sessions. The important thing to note is the setting of absolute paths for the application root and the view directory. This took me some time Googling, so maybe it will help someone in the future.

0 Comments (Show) (Comments are closed for this post)

 
Please note that I am currently unavailable for any large, long term work.