December 15, 2005

Apache and FastCGI Setup

Filed under: General — mmrobins @ 1:54 am

I had a heck of a time setting up Apache on Windows with fastcgi so that I could run a Ruby on Rails app on a production server. The best guide I found for doing this was http://electricvisions.com/rails.html. I used XAMPP for Windows so that I wouldn’t have to download and setup Apache, MySQL and PHP all separately. It’s not too hard to do if you want to do it separately, but after all the uninstalling and reinstalling of those apps I did while trying to get FastCGI to work, I got sick of going through the steps.

I had already installed the One Click Ruby Installer earlier when I was just using Webrick to develop my ruby apps. After installing XAMPP I just ran the FastCGI Installer from the electricvisions guide. I had to copy the mod_fastcgi.so file into the apache modules directory since the installer didn’t find my apache directory in XAMPP automatically. I come to find out later that mod_fastcgi.so is really just mod_fastcgi-SNAP-0404142202-AP2.dll renamed, which is downloadable from the fastcgi site.

Anyway, after that I followed the instructions, made the changes to the httpd.conf and .htaccess, and started up Apache. It looked like fcgi was working! Then I tried to open my rails app and got this in the Apache error log:

[Wed Dec 14 12:02:06 2005] [crit] (OS 3)The system cannot find the path specified. : FastCGI: can’t start (dynamic) server “D:/rails/tooltime/public/dispatch.fcgi”: spawn_fs_process() failed
[Wed Dec 14 12:02:11 2005] [alert] [client 127.0.0.1] FastCGI: failed to connect to (dynamic) server “D:/rails/tooltime/public/dispatch.fcgi”: something is seriously wrong, any chance the socket/named_pipe directory was removed?, see the FastCgiIpcDir directive
[Wed Dec 14 12:02:11 2005] [error] [client 127.0.0.1] FastCGI: incomplete headers (0 bytes) received from server “D:/rails/tooltime/public/dispatch.fcgi”
[Wed Dec 14 12:02:16 2005] [crit] (OS 3)The system cannot find the path specified. : FastCGI: can’t start (dynamic) server “D:/rails/tooltime/public/dispatch.fcgi”: spawn_fs_process() failed
[Wed Dec 14 12:02:26 2005] [crit] (OS 3)The system cannot find the path specified. : FastCGI: can’t start (dynamic) server “D:/rails/tooltime/public/dispatch.fcgi”: spawn_fs_process() failed

I looked up a ton of crap on google to try to fix it to no avail. Finally, I deleted the dispatch.cgi and dispatch.rb from my public directory, leaving just the dispatch.fcgi, and tried again. It seems to work!

It seems like fast cgi is enough in demand that it ought to be included as an Apache module by default, or at least in XAMPP. Maybe someday soon.

3 Comments »

  1. I agree! Last week when I was doing the same thing, I ran into the same problem…

    Hi Matt,
    Just following the highlights of your blog and realized this one is for a different audience than myself, though your trial and error approach is commendable and successful.

    Comment by brendan — December 17, 2005 @ 8:00 pm

  2. you know… I got really excited when i read you post because I’m facing the exact same problem. I deleted dispatch.cgi, and dispatch.rb but no take.. so im wondering if you could post a couple of you config files here. httpd… i wanna see how you set up the virtual host… dispatch.fcgi … .htaccess

    if you don’t mind please post those details..
    -ken
    kojuka@gmail.com

    Comment by Ken — January 2, 2006 @ 3:29 pm

  3. Now that I look back on it, my solution my not even be what did it, but I tried a TON of stuff beforehand. I wish I had documented better what all it was, but I basically just scoured Google for the error messages.

    You might try instant rails as I think they have scgi built in. Also fcgi could soon be integrated into Apache by default.

    Until then, here’s how I setup those files you requested:

    httpd.conf – I’m using and alias instead of a virtual host since I want my rails app to work as a subdirectory of my web server’s root

    Alias /tooltime "C:/rails/tooltime/public/"

    Options ExecCGI FollowSymLinks
    AllowOverride all
    Allow from all
    Order allow,deny
    AddHandler cgi-script .cgi
    AddHandler fastcgi-script .fcgi
    Here's everything in my .htaccess. I commented out the AddHandler stuff since I put it in my httpd.conf

    RewriteBase /tooltime
    RewriteRule ^$ index.html [QSA]
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

    I don't think I changed anything in my dispatch.fcgi except the first line where you point to your local ruby installation

    #!c:/ruby/bin/rubyw.exe
    require File.dirname(__FILE__) + "/../config/environment"
    require 'fcgi_handler'

    RailsFCGIHandler.process!

    Comment by mmrobins — January 5, 2006 @ 5:49 pm

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .