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):
- Install Apache2, latest stable version
- Install MySQL 5.0 Windows Essentials, latest stable version (download the client utilities as well, they are really useful)
- Install the latest Ruby Installer for Windows
- Install Rails using RubyGems (“gem install rails –include-dependencies”)
- Install the latest Ruby For Apache
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!
Similar Posts:

10 Comments
12.10.2005
When you add another application do you just add another virtualhost entry? How do you handle multiple applications under the same server?
I too am looking for an intranet solution and this seems to be the only thing I haven’t seen answered yet.
12.10.2005
To be fair, I haven’t tried yet; the application I set up will be the only RoR to be hosted for a while in that server; but I guess that playing with the routes.rb should help.
In this particular case, Apache listens to port 80, so the application actually is in the root of the webserver, and you access it using “/controllername” in your url; of course you can access all controllers that way, which is not really clean.
If you configure routes.rb, as far as I understood, you can add more levels to your URL, that will be mapped correctly afterwards. This would be a quick one, because you wouldn’t have to touch Apache! :) I should try it.
01.03.2006
Thank you!!! i finally got fcgi working thanks to your directions. seriously…its been a long 2 days. anyways i too have a question about virtual hosting. how do you do with this particular setup?
01.04.2006
No problem :) glad to hear that this has been helpful to you. What do you mean by virtual hosting?
01.04.2006
Did you ever figure out how to host multiple virtual hosts?
01.31.2006
In httpd.conf:
#for Ruby:
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
</IfModule>
#FastCGI Config
FastCgiConfig -maxClassProcesses 10 -maxProcesses 10 -minProcesses 1 -processSlack 1 \
-initial-env PATH=”c:/ruby/bin;c:/windows/system32;c:/windows;C:/mysql/bin;” \
-initial-env RUBYOPT=rubygems
#lunchApp
Alias /lunch “/home/radrails/lunch/public”
<Directory “/home/radrails/lunch/public”>
Options Indexes ExecCGI FollowSymLinks
RewriteEngine On
AllowOverride All
</Directory>
FastCgiServer /home/radrails/lunch/public/dispatch.fcgi -idle-timeout 120 -initial-env RAILS_ENV=production -processes 1
#This should work, and you don’t need a virtual host.
01.31.2006
Thanks Lucas!!
03.15.2006
I have two strange and somewhat conflicting errors. I started trying to get the Apache/FastCGI setup working and now my WeBRICK server which came with RadRails (a RoR IDE based on Eclipse) is giving me the uninitialized constant Mysql error. In addition to that, when I use the Apache configuration, I’m getting the always helpful “Application error: rails application failed to start properly”. Now between the two of these (Apache and WeBRICK) I’d expect one to work considering WeBRICK was working just fine yesterday. Anyone have any thoughts? In fact, I’d be happy if I could just go back to using SOMETHING, but right now, it looks like I broke Rails pretty good. I’ve reinstalled everything from scratch and still haven’t gotten anything to work. Please help!
05.17.2006
I got error when installing Ruby For Apache. It said cannot modify Msvcp71.dll (or else i forget the name) in windows/system32. I click retry but still error, then i ignore it. (I install it as administrator). After that i follow all the instruction, when i start apache i got error “error on httpd.conf line xxx, mod_fastcgi.so not found in path_to/apache/module”
but mod_fastcgi.so is in there.
anyone have solution?? i use winxp sp2
PS: Anyone have mod_fcgid.so for win32 please share it.
05.17.2006
hi there,
unfortunately i can’t help you in this one :( anyone out there have some ideas? thanks