Rack Application Hosting on Ubuntu Jaunty

Thanks to Phusion, setting up a server to run rack and rails applications is very simple.

Ruby

Ruby is an obvious requirement and I’ve covered doing this with standard ruby packages for Ubuntu and Ruby Enterprise Edition, the later of which is recommended for a Passenger based rack application server. You can also use rvm for user accounts.

Standard Ruby

Ubuntu comes with an old fixed version of ruby gems so you need to do the following to get the standard ruby tools installed via packages:

sudo apt-get install ruby irb ri rdoc libruby-extras rubygems ruby1.8-dev
sudo gem install rake
sudo gem install rubygems-update
cd /var/lib/gems/1.8/bin
sudo ./update_rubygems

This will give you the usual ruby commands executed from /usr/bin. You can install and switch between multiple versions of ruby if you so wish.

Ruby Enterprise Edition

Ruby Enterprise Edition is a specific build of ruby by Phusion purposefully designed to perform well in a server environment. This is optional so if you want to run on standard ruby simply skip this section.

I ran the following commands and followed the information given as detailed on the installation page:

cd /opt
wget http://rubyforge.org/frs/download.php/68719/ruby-enterprise-1.8.7-2010.01.tar.gz
tar xzvf ruby-enterprise-1.8.7-2010.01.tar.gz
sudo ./ruby-enterprise-1.8.7-2010.01/installer

Accept the defaults and at the end, the following note is given regarding using with passenger:

Ruby Enterprise Edition is successfully installed!
If want to use Phusion Passenger (http://www.modrails.com) in combination
with Ruby Enterprise Edition, then you must reinstall Phusion Passenger against
Ruby Enterprise Edition, as follows:

  /opt/ruby-enterprise-1.8.7-2010.01/bin/passenger-install-apache2-module

Make sure you don't forget to paste the Apache configuration directives that
the installer gives you.

If you ever want to uninstall Ruby Enterprise Edition, simply remove this
directory:

  /opt/ruby-enterprise-1.8.7-2010.01

If you have any questions, feel free to visit our website:

  http://www.rubyenterpriseedition.com

Enjoy Ruby Enterprise Edition, a product of Phusion (www.phusion.nl) :-)

I like to symlink the version I want to use, so run the following:

sudo ln -s ruby-enterprise-1.8.7-2010.01 ruby-enterprise

To avoid any path issues, I make the modifications outlined in section 3.3 of the documentation by modifying the path in /etc/environment, i.e.:

PATH=”/opt/ruby-enterprise/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”

Passenger

Passenger is very easy to install. There are two sets of instructions depending on whether you want to use the standard ruby installation or ruby enterprise edition.

Using standard ruby

Install the gem and run the installation script. It will tell you what dependencies you are missing and how to install them.

sudo gem install passenger
cd /var/lib/gems/1.8/bin
sudo ./passenger-install-apache2-module

To enable passenger, create /etc/apache2/mods-available/passenger.load with the following contents:

LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.2.9/ext/apache2/mod_passenger.so

and /etc/apache2/mods-available/passenger.conf with the following contents:

PassengerRoot /var/lib/gems/1.8/gems/passenger-2.2.9
PassengerRuby /usr/bin/ruby1.8

then enable the module and restart apache:

sudo a2enmod passenger
sudo /etc/init.d/apache2 restart

The virtual host should point the document root to the public directory of the rails app.

<VirtualHost *:80>
    ServerName www.yourhost.com
    DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
</VirtualHost>

Using ruby enterprise edition

Install the gem and run the installation script. It will tell you what dependencies you are missing and how to install them.

sudo gem install passenger
sudo /opt/ruby-enterprise/bin/passenger-install-apache2-module

To enable passenger, create /etc/apache2/mods-available/passenger.load with the following contents:

LoadModule passenger_module /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.9/ext/apache2/mod_passenger.so

and /etc/apache2/mods-available/passenger.conf with the following contents:

PassengerRoot /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.9
PassengerRuby /opt/ruby-enterprise/bin/ruby

then enable the module and restart apache:

sudo a2enmod passenger
sudo /etc/init.d/apache2 restart

The virtual host should point the document root to the public directory of the rails app.

<VirtualHost *:80>
   ServerName www.yourhost.com
   DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
   <Directory /somewhere/public>
      AllowOverride all              # <-- relax Apache security settings
      Options -MultiViews            # <-- MultiViews must be turned off
   </Directory>
</VirtualHost>

Comments

blog comments powered by Disqus
Fork me on GitHub