Deploying multiple rails apps on Apache using Phusion Passenger

Phusion Passenger (a.k.a mod_rails) is an open-source Apache module that makes deploying rails apps as easy as falling off a log. Its got cool features like deploying multiple rails applications on a single server and is pretty well documented.
This guide aims to get your basic rails application up and running on a linux box (Ubuntu) though other distro’s would work all the same only that some packages or configuration files might be named differently. A name-based virtualhost allows you to assign different hostnames to one IP address. See differences with IP-based virtualhosts here . Note: Dont take my word that this will work, I did this quite a while back and was lazy to write this post then.

  1. Install the Passenger gem. Passenger is available as a gem though you can also install it from source but installing it as a gem works just fine.
  2. $ sudo gem install passenger

  3. After installing the gem install the apache2 module for rails which will guide you through a very user-friendly step by step guide. The module requires a few dependencies which the installer will show you how to install them.After the installation the installer will show you how to modify the apache configuration file. Copy the text to a text file
  4. $ sudo passenger-install-apache2-module

  5. Open your httpd.conf file (located in  /etc/apache2/httpd.conf on ubuntu and /etc/httpd/conf/httpd.conf on RedHat Enterprise 5) and add the following lines. Note that the lines varies depending on your system, what I have would probably be different from what you have.
  6. LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/
    PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11
    PassengerRuby /usr/bin/ruby1.8

  7. Then we need to tell apache to listen for all defined virtualhosts requests.
  8. NameVirtualHost *:80

  9. We can then configure as many name-based virtualhost configurations as we want on the same file. Here’s a sample virtualhost configuration
  10. <VirtualHost *:80>
    DocumentRoot /var/www/askme_avallain_com/askme/public
    <Directory /var/www/askme_avallain_com/askme/public>
    Options Indexes FollowSymLinks MultiViews
    Order allow,deny
    allow from all
    AllowOverride all
    RailsEnv production

  11. Then restart apache ubuntu: $ sudo /etc/init.d/apache2 restartredhat: $ service httpd restart
  12. Then you should be able to access your rails app from the URL assuming that you already have a DNS server map this URL to your server, otherwise you will have to edit your /etc/hosts file and map to your server.

One thought on “Deploying multiple rails apps on Apache using Phusion Passenger

  1. Andrew says:

    Many thanks just what I was looking for.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: