Ruby Enterprise Edition (REE) and Passenger is an idea setup for a VPS or a machine with a limited amount of memory. Both REE and Passenger are developed by Phusion and are tweaked to use about 33% less memory when used together. It’s a fairly simple process to set both up on Ubuntu (10.04 was used in this article). So, let’s begin. You’ll need some basic tools and libraries, necessary to build ruby. If you don’t have them then install them:
sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline6-dev
Then we need to download and install REE:
wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz
tar xzf ruby-enterprise-1.8.7-2010.02.tar.gz
sudo ./ruby-enterprise-1.8.7-2010.02/installer
The installation will run and take some time.
sudo gem install railsI’m going to be using MySQL, so I’ll run through how to install that here. If you are using a different database then google for a way to install it.
sudo apt-get install mysql-serverNow we need to install the MySQL library to speed up database queries. MySQL2 gem is out and works with Rails 3, so I’ll install that. First, we need to take care of the dependencies.
sudo apt-get install libmysql-ruby libmysqlclient-devNow, the actual mysql2 gem installation:
gem install mysql2Let’s install Passenger next. Since we already installed Ruby Enterprise Edition all we need to do is:
sudo /opt/ruby-enterprise-1.8.7-2010.02/bin/passenger-install-apache2-module
If you run the above command it will check to see if you are missing any required software.
sudo apt-get install apache2-prefork-dev libapr1-dev libaprutil1-devThen, re-run the Passenger installation:
sudo /opt/ruby-enterprise-1.8.7-2010.02/bin/passenger-install-apache2-moduleThis installation should tell you to paste some lines into your Apache config file. However, the instructions are a bit outdated and I couldn’t get my system to work accordingly. Instead, I found that, this line
LoadModule passenger_module /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
must be put inside of /etc/apache2/mods-available/passenger.load file.
and inside of /etc/apache2/mods-available/passenger.conf put the following lines:
<IfModule passenger_module>
PassengerRoot /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15
PassengerRuby /opt/ruby-enterprise-1.8.7-2010.02/bin/ruby
</IfModule>Finally, you need to enable the necessary modules (rewrite and passenger), and restart Apache:
sudo a2enmod rewrite
sudo a2enmod passenger
sudo apache2ctl restartAt this point Passenger should be configured and all you need to do is deploy your Rails 3 app and configure it within Apache.
Generally your site’s configuration would be inside of /etc/apache2/sites-available/ (you can call the file mysite) and look something like this:
<VirtualHost *:80>
ServerName mysite
DocumentRoot /var/www/mysite/public
</VirtualHost>
You’ll also need to disable the default and enable your app:
sudo a2dissite default
sudo a2ensite mysite
Restart your apache again if needed.
Related posts:
I would recommend using the Debian package which the Phusion guys make available for installing REE. It will adequately take care of all dependencies when installing upon Ubuntu.
Also heartily recommend making use of RVM for installing REE as an alternative.