Deploy Sintra App on Ubuntu Using Apache2 and Phusion Passenger Module

Check it out http://sinatra.seanbehan.com/
This assumes Apache2 and the Phusion Passenger module have already been installed. If not you can get up to speed w/ this resource http://seanbehan.com/ruby-on-rails/new-ubuntu-slice-apache-mysql-php-ruby-on-rails-git-and/

First you need Sinatra, so install the gem

gem install sinatra

We need a home for Frank, so create the minimum number of directories in our web directory. The public directory is where we’ll server images, stylesheets, javascript etc. The tmp directory will be where we control Passenger.

cd /var/www/sinatra
mkdir myapp
mkdir myapp/tmp
mkdir myapp/public

cd myapp
vim index.rb
#in index.rb
get '/' do
  "Fly me to the moon..."
end

Next we need a configuration file for Rack, important the file extension is “.ru” not .rb!

vim config.ru
require 'rubygems'
require 'sinatra'

Sinatra::Application.default_options.merge!(
  :run => false,
  :env => ENV['RACK_ENV']
)

require 'index'
run Sinatra.application

Set up the virtual host

<virtualHost *>
  ServerName www.myapp.com
  DocumentRoot /var/www/sinatra/public
</virtualHost>

Now you can restart the app if you make adjustments!

touch tmp/restart.txt

Keep on singing :)

Inspired by http://blog.zerosum.org/2008/7/4/passenger-3-sinatra

Protect a Directory with Apache, .htaccess and httpasswd

Apache comes with a command line utility called “htpasswd”. This utility will generate a username and password that you can use to authenticate against using a .htaccess file. Just run the utility like so:

  htpasswd -c /path/to/your/password/directory/and-your-password-filename jane_doe_username

This will prompt you for a password/confirm password.

Keep in mind that this will not create a user on the system. It will just create a password and associate it with a string, that is the username you’ll use to authenticate in your request.

Then you’ll need to add a .htaccess file in the directory that you want to protect, and in that file place the following code.

AuthType Basic
AuthName "Restricted Directory"
AuthUserFile /path/to/your/password/directory/and-your-password-filename
Require user jane_doe_username

Remember that the /path/to/your/password/directory will need to be owned by Apache. on Ubuntu, it’s by default the www-data user. Change ownership like so:

 chown -R www-data:www-data directory