macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Bringing Ruby on Rails with FastCGI into Mac OS X Server

by Luke Burton
03/29/2006

Ruby on Rails (RoR) is a great web application development framework. Although I'm still coming up to speed with actually developing RoR apps, I also wanted to become familiar with the production deployment process. Most of the documentation out there sort of glosses over this plumbing. However, sooner or later you need to get your hands dirty.

Now as a Mac aficionado and OS X Server user, obviously I wanted my RoR installation to be squeaky clean. I wanted to leverage existing components that were already managed by Mac OS X Server, and keep the manually installed components to a minimum. Unfortunately I found a dearth of straightforward instructions in this matter.

What I desired as an outcome was to deploy a RoR application into a directory outside of the normal web document root. I wanted that directory under version control, and I wanted it hosted inside of Apache. I also wanted it to be quick, so FastCGI was absolutely necessary. I also wanted the option to use either MySQL or SQLite. Thankfully, all my wishes came true. Read on to discover how I did it.

Necessary Infrastructure

Let's itemize the components we require to effect our desired setup:

  1. Ruby--the language.
  2. Ruby Gems--the Ruby package manager.
  3. Rails--the development framework based on Ruby.
  4. MySQL--our relational database.
  5. Apache--our web server.
  6. FastCGI--a mechanism to speed up our Rails app inside of Apache.
  7. SQLite--as an alternative relational database.

We have a couple of no-brainers on this list. MySQL, SQLite, and Apache are all bundled into OS X Tiger Server. "Aha," you may say, "and so is Ruby." Yes, but we know that the default installation of Ruby has some problems.

So let's just sidestep the default installation of Ruby, but keep the default MySQL, SQLite, and Apache installations. Plus, we'd like to manage Apache as far as possible through the Server Admin tools. This rolls toward an overwhelming question: how do we most easily install Ruby, Ruby Gems, and everything else without becoming mired in GNU configure scripts?

The answer is DarwinPorts. If you're familiar with FreeBSD's "ports" distribution, or Debian Linux, or Gentoo, this kind of stuff will come as no surprise. For the rest of us, it's a way of easily downloading and compiling source code for open source projects, without having to worry about interdependencies or complex command-line options.

Visit DarwinPorts, grab the package installer, and fire it up. After installation, you should have the command port in your shell path. If not, add /opt/local/bin to your PATH environment variable.

Laying Down Some Ports

DarwinPorts makes life easy by installing everything into /opt/local. This means it pretty much lives in its own little directory tree, with few if any conflicts with existing system libraries. DarwinPorts also looks after its own list of installed packages, making a subsequent clean uninstall an option.

Let's kick off by installing the latest version of Ruby:

# port install ruby

Then, the Gems package manager:

# port install rb-rubygems

Next, we use the Gems package manager to install to the Rails framework:

# gem install rails --include-dependencies

Wow, this is too easy. Next we need the development framework for FastCGI:

# port install fcgi

And also the Ruby interface to FastCGI:

# port install rb-fcgi

And believe it or not, we're almost done. We have one final, manual piece to attend to, and this is the FastCGI module for Apache, aka mod_fastcgi. We first need to download the source code

You will want, at the time of this writing, mod_fastcgi-2.4.2.tar.gz. Extract the files and inside the mod_fastcgi directory, execute the following two lines as per the INSTALL file:

# apxs -o mod_fastcgi.so -c *.c

This compiles the module. Now we need to install it. The installation procedure via apxs is smart enough to modify our Apache's httpd.conf on our behalf:

# apxs -i -a -n fastcgi mod_fastcgi.so

You can go ahead and verify that by finding the LoadModule and AddModule lines in /etc/httpd/httpd.conf that refer to mod_fastcgi.so.

So apart from a bit of fiddling around with mod_fastcgi, our installation is now complete. We just need to complete some final configuration.

Essential Mac OS X Panther Server Administration

Related Reading

Essential Mac OS X Panther Server Administration
Integrating Mac OS X Server into Heterogeneous Networks
By Michael Bartosh, Ryan Faas

Pages: 1, 2

Next Pagearrow