I've been reading alot of forum posts, tutorials, etc., about setting up apache under linux with fastcgi. I'm trying to run fcgi for some of my ruby development (not rails), but I figure it should apply to any language. Please note that I already have apache, fastcgi, ruby-fcgi, and the like already installed on my web box.

Conceptually, I'm having a hard time with it. Does apache spawn the specified fcgi processes as needed? Do I start them along side apache? Basically, I'm trying to get to a point where I am able to ask the proper questions, so apologies if the title is misleading.


Well, in the meantime, I figured this one out. Since there was no concise writeup on this subject, here is the beginning of one. When I have all the bugs ironed out I'll submit this to some tutorial sites.

  1. Make sure that the base fastcgi apache module is installed. If you use ArchLinux as I do, mod_fcgid on the aur works. In other distributions, install either mod_fcgid or mod_fastcgi. (For those who wonder the difference, I don't think there is much, so I went for the one with more activity.)

  2. In your httpd.conf file, activate the module by adding a line to beginning of your LoadModule definitions. Not sure if it matters which distributions, but on Arch it was Loadmodule fcgid_module modules/mod_fcgid.so

  3. Add a new section to your httpd.conf. I put this just under the cgid_module section, but I'm pretty sure location would be arbitrary.

    <IfModule fcgid_module>
      AddHandler fcgid-script .fgci
  4. Now from my understanding, any file having the .fcgi extension in a directory marked ExecCGI will now be handled by the fastcgi module that was installed. I installed this package to give Ruby the fastcgi bindings, an inside an ExecCGI directory, I wrote this test script test.rb.fcgi

    #!/usr/bin/ruby -w
    require 'fcgi'
    count = 0
    FCGI.each_cgi do
      puts "Content-type: text/html\n\n"
      puts "Hello, Ruby! FastCGI(#{count})"
      count = count + 1

Now when you go to that page in your browser, since count is outside the fastcgi loop, it should increment with each page view. If that is so, fcgi is setup correctly.

  • 1
    argh. markdown is giving me some real trouble with this post.
    – sdellysse
    Jan 26 '10 at 23:54
  • Your code was embedded in a list, so 4 spaces indentation are not enough. I made it work with 8 spaces.
    – augustin
    Aug 28 '10 at 0:51
  • 1
    Interesting. So, then one could handle neat .rb files with a <Directory> directive in a <VirtualHost> context, say – AddHandler fcgi-script .rb and FCGIWrapper /path/to/ruby .rb (to remove the hashbang requirement for web scripts). And perhaps Options ExecCGI. Might give this a shot.
    – Benji XVI
    Aug 13 '11 at 0:46
  • in ArchLinux, 'mod_fcgid' is now available in extras, outside of AUR Nov 2 '17 at 2:17

You should look into using Passenger to handle your rails application (even if you are not using any rails features like ActiveRecord etc). There are many websites running on it (plus they have Rails Enterprise, less memory, better performance)

  • As specified in the question, I'm not using rails. But thank you either way.
    – sdellysse
    Jan 25 '10 at 19:14
  • 1
    For the record: Phusion Passenger does not only run Rails applications. It supports Rack, too. So if your web application is using Rack you can try to deploy it with Phusion Passenger.
    – joschi
    Mar 1 '10 at 6:13

Apache should spawn them using the fastcgi interface. It will leave them running for some time, however, and each process is expected to handle more than one request before it is terminated by Apache.


Does apache spawn the specified fcgi processes as needed? Do I start them along side apache?

Apache will spawn them for you. You can set a minimum and maximum number of processes to spawn in your httpd.conf, and it will spawn new ones and kill stale ones based on the volume of incoming requests. As long as you have requests coming in, your process will keep running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.