Intro
There are certain products
which are currently shaking the Ruby / Rails community:
One of them is the infamous
Phusion Passenger which makes deploying Rails applications a piece
of a cake using Apache web servers,
Ruby Enterprise Edition (aka
REE) which promises better memory management and better
scaleability of your Rails applications.
These are really promising
projects and Passenger offers a really elegant and automated setup
which makes it pretty easy to be installed. However, I still keep
seeing people having problems using it with REE and Rails version
2.2.2 on blogs, RailsForum and mostly on IRC.
In this article I will
describe how to set up all of them. Hopefully it will help you
understand the basic ideology how a Ruby environment is set
up.
You will learn how to install
and set up the following products for Rails
development/deployment:
# Apache 2.2
# Ruby Enterprise Edition
# RubyGems 1.3.1
# Ruby on Rails
2.2.2
# Passenger 2.1.0 (note: this
is an edge version, not recommended in production environment, you
can still use 2.0.4)
What you will
need:
# Apache web server already
set up,
# Root privileges to be able
to compile and set up your server
# A basic understanding how
to use the Terminal.
OK, let's get
started.
Install Ruby Enterprise
Edition
Ruby Enterprise Edition (REE)
is a branch of the official Ruby interpreter which is capable of
reducing your Rails applications' memory usage by 33% on average,
as well as improving your applications' performance. First, you
will need to install Ruby Enterprise Edition, you can grab the
source files from here.
Now open up the Terminal and
navigate to your preferred directory where you store your source
files. I've got a directory at /usr/local/src. I like keeping my
stuff tidy.
Let's unpack this package,
navigate to the source and execute the installer:
$ tar xzvf
ruby-enterprise-1.8.6-20080810.tar.gz
$
./ruby-enterprise-1.8.6-20080810/installer
The installer will check for
dependencies and ask where you want to compile REE to. Pretty
straight forward and automated task. Using the default path is not
required but recommended. It's more likely to be installed to
/opt/ruby-enterprise-1.8.6-20080810as the default.
Setup Ruby Enterprise Edition
in your PATH
It will also install RubyGems
(the package manager for Ruby) and the most recent Rails version
for you. Straight out of the box. However, you will more likely to
have stuff to be fixed.
Now you have Ruby Enterprise
Edition installed, let's take a look at your binaries:
$ which ruby
$ which gem
These commands more likely to
return the pre-installed Ruby binaries if you have them, OS X
Leopard comes with pre-installed Ruby and related
binaries.
If you want to use REE as the
primary ruby distribution you can set it up in based on your PATH.
I've created removed the default binaries and created symbolic
links to the new binaries.
Note: Removing is OPTIONAL
ONLY but it makes sense if you don't want to mess up your Ruby
distribution. Messing up multiple Ruby and Gem instances is a
common mistake what people do pretty often.
$ sudo rm
/usr/local/bin/ruby
$ sudo rm
/usr/local/bin/ruby18
$ sudo rm
/usr/local/bin/gem
$ sudo rm
/usr/local/bin/rake
$ sudo rm
/usr/local/bin/rails
$ sudo rm
/usr/local/bin/rails
Now create the
symlinks:
$ sudo ln -s
/opt/ruby-enterprise-1.8.6-20080810/bin/ruby
/usr/local/bin/
$ sudo ln -s
/opt/ruby-enterprise-1.8.6-20080810/bin/gem
/usr/local/bin/
$ sudo ln -s
/opt/ruby-enterprise-1.8.6-20080810/bin/rake
/usr/local/bin/
$ sudo ln -s
/opt/ruby-enterprise-1.8.6-20080810/bin/rails
/usr/local/bin/
Now if you check your
binaries you should have Ruby Enterprise Edition as the primary
ruby version:
$ which ruby
/opt/ruby-enterprise-1.8.6-20080810/bin/ruby
$ which gem
/opt/ruby-enterprise-1.8.6-20080810/bin/gem
Fix and update
RubyGems
OK, now you are ready to go.
Ruby Enterprise Edition comes with pre-installed gems. Let's take a
look at it:
$ gem list
You will probably see Rails
2.2.2 (or the most recent version) installed as well. You may think
you are ready, but actually we still have to fix
something:
Rails version 2.2.2 requires
RubyGems 1.3.1 - or newer - to be installed. Rails was installed
using RubyGems 1.2.0. You can check it yourself:
$ gem -v
1.2.0
I had problems when the
RubyGems update was installed after Rails. Don't worry, we are just
about to fix this. Let's uninstall Rails and its dependencies
without a single sign of fear:
$ sudo gem uninstall
rails
$ sudo gem uninstall
activerecord
$ sudo gem uninstall
actionpack
$ sudo gem uninstall
activeresource
$ sudo gem uninstall
activesupport
$ sudo gem uninstall
acionmailer
Now install the RubyGems
update:
$ sudo gem install
rubygems-update
$ sudo
update_rubygems
This will basically update
your RubyGems package manager to the most recent
version.
NOTE: If the command
"update_rubygems" cannot be found in your PATH then go to your gems
folder and execute it right there:
$ cd
/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rubygems-update-1.3.1/bin/
$
./update_rubygems
If you still haven't
succeeded then you can install it explicitly with Ruby:
$ cd
/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rubygems-update-1.3.1/
$ ruby setup.rb
Fine, now you should be
definitely on version 1.3.1 at least:
$ gem -v
1.3.1
Now let's install Rails
again:
$ sudo gem install
rails
Install and set up Passenger
with Apache
So you already have Ruby
Enterprise Edition with working RubyGems packages such as the most
recent Rails version. Now let's roll on.
There are 2 ways of
installing passenger:
Install the latest official
gem release,
Or you can compile the most
recent beta version from source.
REMEMBER: If you are
installing these applications on a production server, I'd recommend
using the latest official release. As always, you can install
Passenger through RubyGems:
$ gem install
passenger
Now let's compile the the
Apache module and set up Apache:
$
passenger-install-apache2-module
Just follow the instructions,
the installer will locate your web server, compile the module for
it and give you some help how to set it up with it. At the end of
the installer you will see these 3 lines similar to
these:
LoadModule passenger_module
/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/passenger-2.1.0/ext/apache2/mod_passenger.so
PassengerRoot
/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/passenger-2.1.0
PassengerRuby
/opt/ruby-enterprise-1.8.6-20080810/bin/ruby
Just copy and paste these
lines into httpd.conf, and check your configuration and restart
Apache:
$ sudo apachectl
configtest
Syntax OK
$ sudo apachectl
restart
Passenger is a great piece of
software and it's pretty easy to be installed as you've seen. If
you like it, please feel free to donate to Phusion ad get an
Enterprise License.
If you are having problems
using it, don't hesitate and post a comment down here, maybe at
RailsForum or check out the most common affiliates at the support
page.
Post Comments