Acerbic Resonance

There’s no substitute for a good subtitle.

Deploying Ruby On Rails to Feisty Using Capistrano, Apache, and Mongrel

So, I’ve been hacking on a new RoR application for work for the last week or so, and it’s time to get a deployment environment set up so I can deploy as rapidly as I can develop.  I’ve been reading Agile Development With Rails and whilst perusing the chapter on deployment, ran across this site which explains the ins and outs of installing Apache/Mongrel/Capistrano in a deployment configuration on Debian Sarge.  Since I am deploying to an Ubuntu Feisty install, I decided that these instructions are likely close to what I’m after.

Here, then, are my notes about what I had to do to finish the install:

First, there are several differences between Debian Sarge and Ubuntu Feisty, most notably you don’t have to add any extra repositories to get things installed properly.  Here’s my /etc/apt/sources.list:





deb http://us.archive.ubuntu.com/ubuntu/ feisty main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ feisty main restricted
deb http://us.archive.ubuntu.com/ubuntu/ feisty-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ feisty-updates main restricted
deb http://us.archive.ubuntu.com/ubuntu/ feisty universe
deb-src http://us.archive.ubuntu.com/ubuntu/ feisty universe
deb http://us.archive.ubuntu.com/ubuntu/ feisty multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ feisty multiverse
deb http://us.archive.ubuntu.com/ubuntu/ feisty-backports main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ feisty-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu feisty-security main restricted
deb-src http://security.ubuntu.com/ubuntu feisty-security main restricted
deb http://security.ubuntu.com/ubuntu feisty-security universe
deb-src http://security.ubuntu.com/ubuntu feisty-security universe
deb http://security.ubuntu.com/ubuntu feisty-security multiverse
deb-src http://security.ubuntu.com/ubuntu feisty-security multiverse





This is the default sources.list from Feisty, with the comments removed and the multiverse repositories enabled.  With these.

Also note – this machine is already in production with Apache2 configured and running, so I’ve only got to get Ruby, Rails, Mongrel, and Capistrano configured.

Get the repositories up to date:

apt-get update

Now that I’m up to date, I refer back to the [tutorial on how to do this in Debian](http://mongrel.rubyforge.org/docs/debian-sarge.html) and discover which packages I should install first.  They are:

ruby irb rdoc ri ruby1.8-dev libzlib-ruby libopenssl-ruby rubygems build-essential

So, since I tend to like to see what will happen before I actually make changes via apt, I run:

apt-get install ruby irb rdoc ri ruby1.8-dev libzlib-ruby libopenssl-ruby rubygems

build-essential --recon

Which reports:

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following extra packages will be installed:

binutils dpkg-dev g++ g++-4.1 gcc gcc-4.1 irb1.8 libgems-ruby1.8 libopenssl-ruby1.8

libreadline-ruby1.8 libruby1.8 libstdc++6-4.1-dev make patch rdoc1.8 ri1.8 ruby1.8

Suggested packages:

binutils-doc debian-keyring gcc-4.1-doc manpages-dev autoconf automake1.9 libtool

flex bison gdb gcc-doc gcc-4.1-locales libc6-dev-i386 libstdc++6-4.1-doc make-doc diff-doc

ruby1.8-examples

Recommended packages:

libmudflap0-dev

The following NEW packages will be installed:

binutils build-essential dpkg-dev g++ g++-4.1 gcc gcc-4.1 irb irb1.8 libgems-ruby1.8

libopenssl-ruby libopenssl-ruby1.8 libreadline-ruby1.8 libruby1.8 libstdc++6-4.1-dev

libzlib-ruby make patch rdoc rdoc1.8 ri ri1.8 ruby ruby1.8 ruby1.8-dev rubygems

0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded.

Inst binutils (2.17.20070103cvs-0ubuntu2 Ubuntu:7.04/feisty)

Inst gcc-4.1 (4.1.2-0ubuntu4 Ubuntu:7.04/feisty)

Inst gcc (4:4.1.2-1ubuntu1 Ubuntu:7.04/feisty)

Inst libstdc++6-4.1-dev (4.1.2-0ubuntu4 Ubuntu:7.04/feisty) []

Inst g++-4.1 (4.1.2-0ubuntu4 Ubuntu:7.04/feisty)

Inst g++ (4:4.1.2-1ubuntu1 Ubuntu:7.04/feisty)

Inst make (3.81-3build1 Ubuntu:7.04/feisty)

Inst patch (2.5.9-4 Ubuntu:7.04/feisty)

Inst dpkg-dev (1.13.24ubuntu6 Ubuntu:7.04/feisty)

Inst build-essential (11.3 Ubuntu:7.04/feisty)

Inst libruby1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Inst ruby1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Inst libreadline-ruby1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Inst irb1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Inst irb (1.8.2-1 Ubuntu:7.04/feisty)

Inst rdoc1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Inst libopenssl-ruby1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Inst libgems-ruby1.8 (0.9.0-5 Ubuntu:7.04/feisty)

Inst libopenssl-ruby (1.0.0+ruby1.8.2-1 Ubuntu:7.04/feisty)

Inst libzlib-ruby (0.6.0+ruby1.8.2-1 Ubuntu:7.04/feisty)

Inst rdoc (1.8.2-1 Ubuntu:7.04/feisty)

Inst ri1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Inst ri (1.8.2-1 Ubuntu:7.04/feisty)

Inst ruby (1.8.2-1 Ubuntu:7.04/feisty)

Inst ruby1.8-dev (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Inst rubygems (0.9.0-5 Ubuntu:7.04/feisty)

Conf binutils (2.17.20070103cvs-0ubuntu2 Ubuntu:7.04/feisty)

Conf gcc-4.1 (4.1.2-0ubuntu4 Ubuntu:7.04/feisty)

Conf gcc (4:4.1.2-1ubuntu1 Ubuntu:7.04/feisty)

Conf g++-4.1 (4.1.2-0ubuntu4 Ubuntu:7.04/feisty)

Conf libstdc++6-4.1-dev (4.1.2-0ubuntu4 Ubuntu:7.04/feisty)

Conf g++ (4:4.1.2-1ubuntu1 Ubuntu:7.04/feisty)

Conf make (3.81-3build1 Ubuntu:7.04/feisty)

Conf patch (2.5.9-4 Ubuntu:7.04/feisty)

Conf dpkg-dev (1.13.24ubuntu6 Ubuntu:7.04/feisty)

Conf build-essential (11.3 Ubuntu:7.04/feisty)

Conf libruby1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Conf ruby1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Conf libreadline-ruby1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Conf irb1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Conf irb (1.8.2-1 Ubuntu:7.04/feisty)

Conf rdoc1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Conf libopenssl-ruby1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Conf libgems-ruby1.8 (0.9.0-5 Ubuntu:7.04/feisty)

Conf libopenssl-ruby (1.0.0+ruby1.8.2-1 Ubuntu:7.04/feisty)

Conf libzlib-ruby (0.6.0+ruby1.8.2-1 Ubuntu:7.04/feisty)

Conf rdoc (1.8.2-1 Ubuntu:7.04/feisty)

Conf ri1.8 (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Conf ri (1.8.2-1 Ubuntu:7.04/feisty)

Conf ruby (1.8.2-1 Ubuntu:7.04/feisty)

Conf ruby1.8-dev (1.8.5-4ubuntu2 Ubuntu:7.04/feisty)

Conf rubygems (0.9.0-5 Ubuntu:7.04/feisty)

Ok, that all looks good, so off we go to let it actually run.  I’m going to go re-fill my water bottle.

Zzzzz……

Alright, that’s done.  Up next is to install rails, mongrel, capistrano, and other supporting software via gem:

root# gem install rails --include-dependencies

root# gem install termios --include-dependencies

root# gem install capistrano --include-dependencies

root# gem install mongrel --include-dependencies

root# gem install mongrel_cluster --include-dependencies

Important Note: I had to choose which version of mongrel to install, as well as which version of fastthread, which is a dependancy of mongrel.  Simply choose the lowest numbered gem offered for your platform.

At this point, we should have a working Rails installation.  To test it, we’ll follow a few more instructions from the Debian tutorial to put together a quick “Hello World” app.  Log in as a normal user, and do the following:

kimball:~$ rails test_app

Which should puke:

The program 'rails' is currently not installed.  You can install it by typing:

sudo apt-get install rails

Make sure you have the ‘universe’ component enabled

-su: rails: command not found

But, didn’t we install it?  And what’s with this package?  I thought we used a gem to install it…?  So, now we have a dilemma, and since I’m writing this as I go along, I’m going to have to make a decision and document the results, blithely ignoring the fact there are other ways to do this.

Typically I prefer to use the built in package manager to handle all my software installs, but in this case, I’ll make an exception and keep the version of rails that was installed via gem.  This means I’m going to have to update my path to include the correct location for the rails binarys I’ll need.  A quick spelunking trip into my filesystem reveals that they are installed here:

root# locate rails | grep bin

...

/var/lib/gems/1.8/bin/rails

...

So, there is a rails binary in /var/lib/gems/1.8/bin/.   I can add /var/lib/gems/1.8/bin to my path by editing /etc/profile and adding the following after the first comment lines:

PATH=$PATH:/var/lib/gems/1.8/bin

So, now I’ll try to create a quick “Hello World” rails app again.  Log out/in first to have the path changes occur.

kimball:~$ rails test_app

create

create  app/controllers

create  app/helpers

create  app/models

...

create  log/production.log

create  log/development.log

create  log/test.log

So, that appears to have worked.  Next, let’s create a controller and a quick view:

kimball:~/test_app$ script/generate controller HelloWorld index

exists  app/controllers/

exists  app/helpers/

create  app/views/hello_world

exists  test/functional/

create  app/controllers/hello_world_controller.rb

create  test/functional/hello_world_controller_test.rb

create  app/helpers/hello_world_helper.rb

create  app/views/hello_world/index.rhtml

Modify app/views/hello_world/index.rhtml to be:

<h1>Hello World</h1>

<p><%= Time.now.to_s(:long) %></p>

And let’s see how we did:

kimball:~/test_app$ mongrel_rails start -p 5000

** Ruby version is not up-to-date; loading cgi_multipart_eof_fix

** Starting Mongrel listening at 0.0.0.0:5000

** Starting Rails with development environment...

** Rails loaded.

** Loading any Rails specific GemPlugins

** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).

** Rails signals registered.  HUP => reload (without restart).  It might not work well.

** Mongrel available at 0.0.0.0:5000

** Use CTRL-C to stop.

** INT signal received.

(I had to change my port number to 5000, as 3000 is already used by something else)

Ok, it appears to be running – hitting the server like this: http://myhost.com:5000/hello_world shows this:

railsHelloWorld

So, I now have Rails installed and running a mongrel instance on my server.  Great!  That’s as far as the first tutorial went, so now I’ve got to go back to the pragmatic book to see what’s got to happen next to get capistrano going.

And, since this book is filled with tons of great information on just about every aspect of Rails development and deployment, instead of regurgitating it here, I encourage you to pick up your own copy and follow the rest of the instructions starting on page 623 yourself.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.