Rails, Apache 2.0, FastCGI on Windows

In advance of running a Rails application on a Windows machine, I’ve been trying to get Rails running on my local WinXP machine to ensure a smooth transtion. I followed the instructions on the rails wiki, and while I could ge the app running, it was very slow - requests were taking between 4 and 5 seconds. It seemed to be an issue with Ruby, not Apache. The ruby process was coming close 100% on each request. After following this blog entry, it’s running well, and very fast. Thanks, Dema :)

UPDATE: the above link is no longer working, and as it turns out, I’d forgotten one of the steps. I dug up a chaced version of the post and am posting it below, mainly so I have it going forward, but also since I suspect someone may need it.

But I have good news, I finally managed to get it working well enough these days. And to spare you, who are in the same boat, the
same trouble, here are some useful tips.

First, let’s cover the basics:

Install Apache2, latest stable version
Install MySQL 4.1 Windows Essentials, latest stable version (I will only cover MySQL as a db backend here)
Install the latest Ruby Installer for Windows
Install the latest Ruby For Apache

Now, make sure you have mod_fastcgi.so in your Apache2\modules folder and that you have mysql.so and fcgi.so in your
ruby\lib\ruby\site_ruby\1.8\i386-msvcrt folder.

Start a normal IRB session and type require ‘fcgi’ and require ‘mysql’. You should get ’=> true’ as a response from both.
Make sure you have these directives in your Apache2 httpd.conf file:

LoadModule fastcgi_module modules/mod_fastcgi.so


AddHandler fastcgi-script .fcgi

Now, a typical Virtual Host entry that should point to your Rais application would look like this:


DocumentRoot c:/dev/myrailsapp/public
ErrorLog c:/dev/myrailsapp/log/server.log

Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny

Remember to add a ‘Listen 3000’ directive as well up in the httpd.conf file if you’re going to use that port.
Now, in your dispatch.fcgi file that resides in your Rails app public\ folder, make sure the shebang line is correct:

#!c:/ruby/bin/ruby

Finally, in your .htaccess file that resides in the same folder as the dispatch.fcgi file, change the rewrite rule that points to the
‘dispatch.cgi’ file and replace it with ‘dispatch.fcgi’.

So far, pretty standard stuff. Now, let’s get a little fancier. To make Apache2 more conservative when running on Windows, go back to
the httpd.conf file and add these lines:

EnableSendfile Off
EnableMMAP Off
Win32DisableAcceptEx

update after upgrading MySQL from 4.1 5.0 I needed to copy libmysql.dll from the mysql bin dir to windows/system32 to fix a mysql error..

Post a Comment

Your email is never published nor shared. Required fields are marked *

*

*