How to Install Ruby on Rails in Windows 2003

Great day; my first full Ruby on Rails application is up and running in production environment. It is installed in an intranet server at my employer’s premises, so I will not be able to show it :(

But anyway, here goes some tips and tricks for installing such an application in a Windows 2003 server, using a MySQL 5.0 database, and running it with Apache 2.0 with FastCGI (pretty latest stuff altogether, isn’t it??? :)

First of all, check this awesome article and follow the instructions (here goes a local copy, if the URL does not work). That article gives almost everything you need to put the whole thing to run; this one just gives some details that I found useful this afternoon.

The most important, the packages to install (inspired from the above blog entry):

The last one includes FastCGI and the Ruby-MySQL libraries. Beware though, that in my case I had an odd dialog box saying “xxxxx.DLL does not exist in C:\WINDOWS - Abort - Retry - Skip”; I just clicked on “skip” and everything went fine… maybe it has to do with the fact that this was Windows 2003… who knows!

Once you have installed these packages, the fun begins ;) Configuration time!

Apache’s httpd.conf file (in the conf subdirectory of the local Apache installation)

I assume here that your application is in “C:/path_to_your_rails_app”:

Remember NOT to use backslashes but common *nix slashes… Also, do not use quotes in your PATH variables; also, use the 8.3 filenames for the PATHs as well (you can retrieve them using “dir /X” in the command line).

Another important thing: if your application uses HTTP Authentication, add the " -pass-header Authorization" parameter to the FastCgiServer directive, otherwise, you will not be able to retrieve the credentials of the logged in user in your application code…

Remember to restart Apache after every modification to httpd.conf!

In your /rails_app/public/.htaccess file

Change this line from

RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

to this:

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

so that you use FastCGI instead of “classic” (and slow) CGI.

The odd, undocumented, hidden trick

Once you’ve done all of this, guess what; your application will NOT work.

To fix it, you must do the following: go to C:\mysql\bin (or the bin file of your MySQL installation) and you will see a single DLL file (the name is something like libmysql.dll, I do not remember right now; but there is only one DLL file). Well, for the application to run, copy this file and paste it into C:\WINDOWS. Exactly, just do this, otherwise you will have a awful “Uninitialized constant mysql” error…

This last trick, It appears in comment 13 in the blog entry previously referenced, but in my case it worked if I copied it into C:\WINDOWS instead of C:\WINDOWS\SYSTEM32…

Restart Apache, browse to your web server, and voilà! Hope this helps!