markhorrocks markhorrocks - 5 months ago 12
Ruby Question

How to deploy a Rack-based Ruby application with Apache 2 and Passenger?

I have written a very simple "hello world" ruby script which I want to run under apache2 (2.4) and passenger on Ubuntu 14.04. This is not a rails app and I don't want to use the rails framework, this is just a single page application.

So far, all I can get is a directory listing. Here are my files.


class Uptime
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]


source ''
gem 'rack', '~>1.5.1'

require './uptime'


LoadModule passenger_module /usr/lib/apache2/modules/


<IfModule mod_passenger.c>
PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
PassengerDefaultRuby /home/mark/.rbenv/shims/ruby


<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

PassengerRuby /home/mark/.rbenv/versions/2.3.1/bin/ruby

<Directory /var/www/html>
PassengerEnabled on
Allow from all
Options -MultiViews
Require all granted

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined



Passenger expects that your app has a public and a tmp directory:

  • The public directory has to be your DocumentRoot. It will be served by Apache if Passenger is disabled / not working, so nobody can see your application's source code.

  • The tmp directory is used for Passenger's restart.txt.

Your directory tree should look like this:

├── uptime.rb
├── Gemfile
├── public/
└── tmp/

In your config:

<VirtualHost *:80>
    DocumentRoot /var/www/html/public
    # ...

    <Directory /var/www/html/public>
        # ...

    # ...