Category Archives: Apache

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/mod_passenger.so
    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>
    ServerName example.domain.com
    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
    </Directory>
    </Virtualhost>

  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 http://domain.example.com 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 domain.example.com to your server.
Advertisements