Learning Rails: Installing Rails, Part 1 – Debian

Table of Contents

Before I can write code, I need to install Rails.  The best place to get started is the Ruby on Rails Download page. I work on both a Windows box and a Debian box, so I’ll need to install Rails on both machines. This time, I’m going to focus on installing Rails on the Debian box, which is actually the server where this project will eventually run. When I’m doing a lot of command line work, I prefer to work on the Debian box.

Installing Ruby and RubyGems

Note: I’m running a clean install of Debian Squeeze for this project. If you aren’t, your steps might differ. Follow the instructions at the Rails download page.

First, I install ruby.

$ sudo apt-get install ruby
Reading package lists... Done
Setting up ruby1.8 ( ...
Setting up ruby (4.5) ...

$ ruby --version
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]

That looks good. Now I need RubyGems.

RubyGems is the standard package manager for ruby.  If you need a Ruby library, like Rails, there’s a good chance it’s available as a gem. So, I download and install the latest version.

$ wget http://rubyforge.org/frs/download.php/75309/rubygems-1.8.10.tgz
2011-10-19 21:49:25 (351 KB/s) - `rubygems-1.8.10.tgz' saved [249683/249683]

$ tar -xzvf rubygems-1.8.10.tgz

$ cd rubygems-1.8.10

$ sudo ruby setup.rb
RubyGems 1.8.10 installed
RubyGems installed the following executables:

That was pretty easy.

Read the rest of this entry »

FcgidMaxProcessesPerClass Broken on Debian Squeeze

The server went down today with an out of memory kernel panic when Natural Jenius was under heavy load.  I started watching the system, and we were getting a separate php5-cgi process for each simultaneous request.  According to the Apache documentation, FcgidMaxProcessesPerClass is supposed to limit the number processes spawned per virtual host.  the default value is 100, but for a server our size it should be at about 2. So I fired up vi to edit the configuration.

$ cat /etc/apache2/mods-enabled/fcgid.conf
AddHandler fcgid-script .fcgi
 FcgidConnectTimeout 20
 FcgidMaxProcessesPerClass 2
$sudo service apache2 restart
 Restarting web server: apache2 ... waiting ...

I used the Apache benchmark tool from another machine to test the configuration. I started with twenty requests, five simultaneously.

$ ab -n 20 -c 5 naturaljenius.com/category/programming
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking naturaljenius.com (be patient)...apr_poll: \
    The timeout specified has expired (70007)

What the…? When I checked the server, there were a boatload php5-cgi processes, one for each request. The server was extremely slow and running out of RAM quickly.

Read the rest of this entry »