How do I set up a Sinatra app under Apache with Passenger?

14,587

Solution 1

Basic directory structure:

app
|-- config.ru         # <- rackup file
|-- hello-app.rb      # <- your application
|-- public/           # <- static public files (passenger needs this)
`-- tmp/              
    `-- restart.txt   # <- touch this file to restart app

Virtual host file:

<VirtualHost *:80>
  ServerName    app.example.com
  DocumentRoot  /path/to/app/public
  <Directory    /path/to/app/public>
    Order       allow,deny
    Allow       from all
  </Directory>
</VirtualHost>

config.ru

# encoding: UTF-8
require './hello-app'
run Sinatra::Application

hello-app.rb (sample application):

#!/usr/bin/env ruby
# encoding: UTF-8
require 'rubygems' # for ruby 1.8
require 'sinatra'

get '/hi' do
  "Hello World!"
end

restart.txt is empty.


Mildly useful links:

Solution 2

Example vhost file for rack app with passenger:

<VirtualHost *:80>
 ServerName   server.local
 ServerAlias  *.server.local
 DocumentRoot /dir/public
 RackEnv      development
 <Directory /dir/public>
 Order allow,deny
  Allow from all
 </Directory>
</VirtualHost>

Example Config.ru:

require File.expand_path('../boot.rb', __FILE__)
use Rack::Middleware
run Rack::Cascade.new([array])
Share:
14,587

Related videos on Youtube

kch
Author by

kch

Updated on July 29, 2020

Comments

  • kch
    kch almost 4 years

    Let's say I have the simplest single-file Sinatra app. The hello world on their homepage will do. I want to run it under Apache with Phusion Passenger, AKA mod_rails.

    • What directory structure do I need?
    • What do I have to put in the vhost conf file?
    • I understand I need a rackup file. What goes in it and why?
  • kch
    kch almost 14 years
    what's boot.rb and Cascade in your config.ru?
  • Capstone
    Capstone about 11 years
    I'm trying to achieve the same thing, but I have an existing virtual host config. There is documentation at their site, but following that exactly, leads to an error saying: