Saturday, September 24, 2005

Rails on Windows (and Apache2)

First of all, I would never recommend using a Windows server -- for anything, really. However, I understand that there are times when you have no choice. I, for instance, have a server that's running Windows (although if asked later, I will deny it). Sadly, because of the web-applications I'm hosting, a *nix system isn't an option. Fortunately I am able to side-step IIS. I'm running Apache 2 instead. (Actually, I am running IIS, but on a different port -- I use Apache as a proxy)

Hooray for a small victory!

Anyway, I -- as well as many others -- have not had a great time trying to get Rails applications running efficiently on Win/Apache. Getting FCGI working is a bear. Getting it working correctly is nigh impossible. CGI is sooo slow. And if, by some miracle, the planets are aligned and the server is working right -- ruby forgets how to talk to MySQL. *sigh*

After consulting everyone's best friend, Mr. Google, I found that a lot of people seem to be having problems on Windows. Some like mine, others not. None of the posted suggestions seem to work.

So what did I do? Well, after my impersonation of a Tourette's syndrome sufferer, I rolled up my sleeves and dug in. After messing around with it for far too long, I finally found a combination that works! (For me, at least.) Believe it or not, Rails apps are most stable/fast using the new SCGI Rails Runner.

Overall, it was actually quite painless to install. Just follow the installation instructions, configure apache, start the scgi_rails script (using the -D flag), restart apache, and your almost ready to go. In my case, at least. I was still having the mysterious ruby error (GPF) stating it couldn't load libmysql.dll.

To get it to work correctly, I had to do one more thing: Move the libmysql.dll (for me it was at C:\Program Files\MySQL\MySQL Server 4.1\bin) to the ruby/bin folder (C:\ruby\bin).

And now, finally, everything is right as rain. In fact, the two Rails applications I've tested are running faster on that machine than I've ever seen.

Hopefully SCGI will be as easy for you to install as well. But of course, with Windoze, your results may vary.