Here's a quick tutorial showing how to deploy a Sinatra web application on MacOS X, with Apache web server using the Passenger plug-in.
Sinatra is a tiny web framework that seems to be gathering steam. It's claim to fame is its compact size, and a clear "no magic" approach to web development. Sign me up! Open a terminal and paste this to get started.
sudo gem install sinatra
Make and Deploy Sinatra's "Hello World!"
To ultimately deploy your app, you're going to have to make some extra folders and configuration files. Passenger is designed to deploy Rails apps, so to get Passenger to reload your changes, you have run 'touch tmp/restart.txt' in the terminal. Open the Terminal, and change directories to a good place to put your Sinatra application. Run the following commands in the Terminal to create the files and directories needed. I put everything in /Timestretch/ruby/hello/.
Put this in "config.ru". Note this file has an unusual '.ru' extension. This file is a 'Rack Up' configuration file. Ruby Rack is a middleware that sits between the web server and web framework.
Put this in "hello.rb"
require 'rubygems' if RUBY_VERSION < '1.9'
class Hello < Sinatra::Base
get '/' do
Passenger is a plug-in available for both Apache and Nginx web servers. It allows you to simply place the web application folder in the document root and serve up your web site. I used the Apache2 module.
sudo gem install passenger
Passenger will print out a snippet to paste into the Apache configuration file. This is what mine output. Don't just copy mine. Use the output printed by the script.
Put the snippet that looks something like this in /etc/apache2/httpd.conf.
I also made up a test domain name and put it in /etc/hosts file. This lets me visit http://hello.timestretch.com/ in the browser and test the website as if a client were using it.
Add this to /etc/hosts
Open up the /etc/apache2/extra/httpd-vhosts.conf file and add the following. This will allow you to use http://hello.timestretch.com/ in your web browser to connect and test your web application.
Deny from all
Allow from localhost
Allow from 127.0.0.1
Now that everything is all set, check the apache configuration file. Fix any typos or errors it reports. Then restart Apache.
sudo apachectl graceful
Now you can visit the url http://hello.timestretch.com/ in the web browser. If all went well, you will see "Hello World!"
If you didn't get the results you expected, check the error log in /var/log/apache2/error_log and reload your page.