Moving to Future Hosting, Part III

In this episode of Moving to FutureHosting, I’ll be installing and configuring Apache2, the mpm-worker multiprocessing module, passenger (aka mod_rails), Ruby, Ruby on Rails, and all associated cruft. I’ve done this before on Ubuntu using aptitude, but since FutureHosting runs CentOS, which uses the yum package manager, this will be a new experience for me.

Apache2

My FutureHosting box came with Apache2. /usr/sbin/httpd -v reports Server version: Apache/2.2.9 (Unix), which seems fine.

Which MPM?

Apache2 supports multiple concurrency models for handling more than one connection at once. Each model is implemented in a Multi-Processing Model (MPM). prefork-mpm causes Apache to fork off a number of processes on startup, each of which will process some requests. worker-mpm creates multiple worker threads within a process to handle requests. I’ve read that the latest versions of Passenger work well with worker-mpm, which has the added advantage of being less memory-hungry than a bunch of forked processes.

I don’t know how to tell what MPM the existing install is using. I grep‘d all the LoadModule directives in the HTTP configuration files in /etc/httpd/conf/ but I don’t see anything pertaining to an mpm. /usr/sbin/httpd -l lists prefork.c but no worker.c. This tells me the version of Apache that comes with CentOS 5 is built without support for worker-mpm. Ubuntu has handy aptitude packages for both MPMs, so you install the one you want and it configures Apache accordingly. CentOS seems to be missing that. I’ll go with prefork for now until I can figure out how to change it.

Ruby

The latest version of Ruby available as a yum package is 1.8.5-5. Um, no. That’s ancient. That means I have to build from source. Out-fucking-standing. Why does anyone run CentOS anyway?

No matter, the forum thread here pointed me to a custom repository some guy is running, with the latest Ruby 1.8.6 bits. Pathetic that it came to that. I installed ruby, ruby-devel, ruby-irb, ruby-mysql, and ruby-rdoc.

Ruby Gems

I installed Ruby Gems from the same source as above, which then pulled in a dizzying dependency chain of additional packages, nearly 60 (!!) in all. The installation seemed to work, though, so I can’t complain.

Ruby on Rails

Rails is easy. sudo gem install rails. QED.

Passenger

Phusion Passenger runs Rails apps in Apache fast and reliably. What more is there to say?

It’s distributed as a Ruby gem, so

sudo gem install passenger

And Passenger is installed. But it needs to be configured as a module in Apache2. For that there’s

sudo passenger-install-apache2-module

Which builds the Apache module from source, and spits out the appropriate verbiage for httpd.conf. The httpd configuration stuff is in /etc/httpd/conf, which includes files in /etc/httpd/conf/extras. In keeping with this idiom, I created a new file, /etc/httpd/conf/httpd-passenger.conf, to contain the Passenger-related configuration:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby /usr/bin/ruby

which I include in /etc/httpd/conf/httpd.conf using an Include directive.

After that, sudo apachectl restart and the module was loaded.

Ruby Enterprise Edition

Phusion (makers of Passenger) offer an ‘enterprise’ edition of the Ruby interpreter that works with Passenger to reduce memory load and increase performance. I’ve never used it before, but I’d like to give it a try.

After downloading and extracting the source tarball, there’s no familiar configure/make/make install cycle. Instead there’s an installer script that takes you through the installation.

I accepted the default install directory (/opt/ruby-enterprise-1.8.6-20080810), and off it went building from source. I don’t have any Postgres components installed, so it choked trying to install Postgres support, which I don’t give a shit about. I can always install it later with /opt/ruby-enterprise-1.8.6-20080810/bin/ruby /opt/ruby-enterprise-1.8.6-20080810/bin/gem install postgres.

And that was it. To cause Passenger to use Ruby EE, I changed the PassengerRuby line in the httpd-passenger.conf file to:

PassengerRuby /opt/ruby-enterprise-1.8.6-20080810/bin/ruby

Too easy!

Testing

To verify Passenger and Ruby EE are working, I need a Rails app to serve. I’ll create one in my home directory and make Apache use that as the root for the default VirtualHost:

rails passtest

to create the project.

script/generate controller itworked

failed with:

Rails requires RubyGems >= 1.1.1 (you have 0.9.4). Please `gem update --system` and try again.

Yikes! I had no idea I was running ancient gems. sudo gem update --system made quick work of that problem.

Now, as I was saying,

script/generate controller itworked

It spit out an annoying error:

/usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/rails_generator/lookup.rb:211:in 'each' is outdated

but otherwise seemed to work.

Now ~anelson/passtest/public is the public root for my rails app, which I need to point Passenger to.

For now I’ll just use one of the VirtualHost entries in /etc/httpd/conf/extras/httpd-vhost.conf, since I’m just testing.

And…it worked! I pointed DocumentRoot to the public folder in my Rails project, and got the default Rails screen. It seems to be working. Yay.

Tags: , , , , , ,

One Response to “Moving to Future Hosting, Part III”

  1. anelson Says:

    rails_user wrote:
    >How did you fix
    >It spit out an annoying error: /usr/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/rails_generator/lookup.rb:211:in `each’ is outdated

    I didn’t fix it. I haven’t yet figured out why that happened. It didn’t seem to hurt anything, so I left it for another day.

Leave a Reply