(2016 Update: Links are dead)

I recently worked on a project that required me to host a rails application on Windows XP Home, something I had no experience with but took on as our options were limited. We wanted a load-balanced server running a Rails app with a MySQL database. An XAMPP install was also being used by another group on the server, through which we had MySQL access.

I learned quite a bit trying to get it working, and I hope I can help someone else with how I did it. I started this last fall, so some of the software may have been updated. Also, I would like to thank Joseph Jaramillo for his post on Deploying to IIS with lighttpd and Mongrel which was a huge help setting this up.

1. Install Ruby

For Ruby, I used the 1.8.6 one-click installer. Download, and install.

2. Install Ruby Gems

Hop on over to RubyForge and grab the latest zip file (rubygems-1.3.2.zip as of this article). Download, and install.

3. Install Rails and Mongrel

Open a command prompt and run gem install rails to get rails installed. Next, run gem install mongrel mongrel_service which will install the Mongrel server.

4. Setup a Rails Application

I will assume you have setup a Rails application before, and know how to create one from scratch or that you have one ready to drop in to be served. If you are not that experienced with Rails yet, I would recommend starting with Mongrel only for development.

Try out your Rails install by opening a command prompt to your Rails directory and running script\server (note the backslash), and then see if rails loads at http://localhost:3000/. You may get a Windows Security Alert that you need to unblock to allow outgoing connections. At this point, you have enough to run a Rails server for development, but the aim of this article is to be more robust.

5. Install lighttpd

Lighttpd is a great lightweight server that will be an excellent load-balancing proxy for this setup. We could have hooked into the Apache install from XAMPP, but I did not want to cause any problems for the group running that server. To install lighttpd, download the most recent lighttpd installer from the WLMP project (I used LightTPD-1.4.22-1-Win32-SSL.exe). I had major problems with a Cygwin1.dll from an openSSH install conflicting with the ones for lighttpd, and had to remove the openSSH Cygwin1.dll before lighttpd would work properly; you can check for this error by running lighttpd from a command prompt and seeing if you get an error.

6. Install Windows Server 2003 Resource Kit

To get lighttpd running as the kind of service we need, download and install the Windows Server 2003 Resource Kit.

7. Install Mongrel Rails Service

We are going to have two Mongrel servers serving our Rails application, although you can run more (See How Many Mongrel Instances Should I Run?). To do this, open a command prompt and goto your Rails app directory. For each Mongrel server you want to run, enter the following command:
mongrel_rails service::install -N rails_app_4001 -p 4001

Increase the number by one for each service (4002, 4003, etc) as you run the command. This command will install Windows services that will run our Mongrel servers in the background. To start these servers, run the following command for each server, incrementing the number for each server (4001, 4002, etc.):
net start rails_app_4001

To make it easy to start and stop these servers, create a mserver.bat file in your Rails directory with the following contents:

@echo off
net %1 rails_app_4001
net %1 rails_app_4002

Add additional lines for each extra Mongrel server, again incrementing the number. This script will allow you to start/stop all the servers by opening a command prompt, going to the Rails directory, and typing mserver.bat start or mserver.bat stop, which will come in handy when restarting your Rails app. To test if these servers are running, open a web browser and navigate to ports 4001, 4002, etc on your server and see if your Rails app shows up.

8. Setup lighttpd Proxy

Download and install Joseph Jaramillo’s lighttpd conf file to your Rails directory, and put it in your config directory.

Edit the file with an app that supports UNIX-style line endings (not notepad), changing the following values:

var.basedir = "C:/Rails/myrailsapp"
(point to your Rails app directory, use forward slashes)

server.bind = ""
(do not bind to a specific address)

server.port = 3000
(the port you want your users to use. 80 is a good default, or if already used as in my case, 3000)

and under proxy.server, add extra entries for any additional Mongrel servers you are running.

Next, setup lighttpd to run as a Windows service. Follow Joseph’s instructions on step 3, of course changing the AppParameters to use the path to your lighttpd config file in your rails directory. Test your setup by pointing your browser at your server’s main address (or other port if you chose one other than 80), and you should see your Rails application!

If you have any comments, suggestions, or problems let me know in the comments.