How to use mod_fcgid to set up Rails app on Apache2

Yesterday I tended to install mod_fcgid on my apache2, instead of mod_fastcgi or mod_ruby because of some insecure pipe problem with the laters. And To be pride and surprised, the author of mod_fcgid is Chinese people, but that doesn’t help me to come over the problems I face, so I need to handle them on my own. I’d like to review what I encountered and am hoping to help other people who are humbled by this.

My machine deploy: Ubuntu dapper, apache 2.0.58, Ruby 1.8.4, Rails 1.1.4, (mod_fcgid 1.10, libtool, ruby1.8-dev)

1. Installing mod_fcgid

Here is the problems ever, if you don’t want to read this, you can read the next paragraph which is correct steps.

Download mod_fcgid 1.10 and follow the INSTALL.txt step by step. There I ever had two problems. I folllowed by INSTALL.txt and it returned error no matter what I did. So I think I need to reinstall apache2 statically to load mod_fcgid module. Follow INSTALL.txt and Line:


./configure --prefix=/usr/local/apache2 --enable-dav --enable-so
--enable--maintainer-mod --enable-shared=max --enable-module=most --enable-fcgid

then when adding

LoadModule fcgid_module modules/mod_fcgid.so

to my httpd.conf and restart my apache2, I got error,


Syntax error on line 233 of /usr/local/apache2/conf/httpd.conf:
module fcgid_module is built-in and can't be loaded

Note ‘–enable-fcgid’. That’s because I have already installed mod_fcgid statically, I can’t use LoadModule to load a static build-in module, get it? Because it is already statically installed in apache2, and LoadModule is used to load a dynamic module. That is the reason why it returned error. So I had to reinstalled apache2 by this below to dynamically load modules at latter day.


./configure --prefix=/usr/local/apache2 --enable-dav --enable-so
--enable--maintainer-mod --enable-shared=max --enable-module=most

Okay! Then needed to install mod_fcgid dynamically. Follow the INSTALL.txt file, I got an error again:

dlname not found in apache2/modules/mod_fcgid.la.

Yes, apache2 failed to build the mod_fcgid.so and it was not in apache2/modules directory. That problem is because of the version of libtool in apache2/build. After I update my libtool by

sudo apt-get install libtool

I still had same error. Oh I forgot although I installed libtool, but I needed to do this

sudo cp /usr/bin/libtool /usr/local/apache2/build

to override previous libtool in apache2.

Ok, this time we can reinstall mod_fcgid again by steps in INSTALL.txt and it can be correctly installed.

2. Using gem to install fcgi

Next we need to install fcgi by type:

sudo gem install fcgi

But the annoying error appeared again. Said:

ERROR:  While executing gem ... (RuntimeError)
ERROR: Failed to build gem native extension.
Gem files will remain installed in
/usr/lib/ruby/gems/1.8/gems/libxml-ruby-0.3.6 for inspection.
ruby extconf.rb install libxml-ruby

That indicated me to install ‘ruby-devel’ package, named ruby1.8-dev, so type:

sudo apt-get install ruby1.8-dev
sudo gem install fcgi

Well, problem was resolved, again.

3. Setting up Rails app, such as typo

Set up your Rails app by refering this page, and add this code below in your httpd.conf (warsaw is localhost name)


LoadModule fcgid_module     modules/mod_fcgid.so

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /home/alex/httpd
    ServerName warsaw
    ErrorLog logs/dummy-host.example.com-error_log
    CustomLog logs/dummy-host.example.com-access_log common

redirectMatch ^warsaw/blog$ http://warsaw/blog/
    redirectMatch ^warsaw/radiant$ http://warsaw/radiant/
    #redirectMatch ^/$ http://warsaw/blog

Alias /blog "/home/alex/httpd/typo/public/"
    Alias /radiant "/home/alex/httpd/radiant/public/"

<Directory "/home/alex/httpd/typo/public">
        Options All ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        AddHandler fcgid-script .fcgi
        RewriteBase /blog
    </Directory>

<Directory "/home/alex/httpd/radiant/public">
        Options All ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        AddHandler fcgid-script .fcgi
        RewriteBase /radiant
    </Directory>

<Location /blog>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    </Location>

<Location /radiant>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    </Location>
</VirtualHost>

Notice that you should change the ‘.htaccess’ file name to ‘htaccess’ in app’s public/ directory. If doesn’t, it will appear disgusting error again.

Reference:[Integrating typo, Using mod_fcgid for Ruby on Rails Applications, Ruby on Rails and Ubuntu, Installing Typo]

5 Responses to “How to use mod_fcgid to set up Rails app on Apache2”


  1. 1 Lars November 10, 2006 at 2:41 am

    One quick mention is that you do not want to use puts() as a debugging tool. If you see a bunch of entries like the below in your webserver error log, you probably have a puts() somewhere …..
    malformed header from script. Bad header=ctrl =>admin act =>account: dispatch.cgi

    The text from ctrl => admin act => account can be anything based on what you put in your puts() statement….

  2. 2 trailsiteks September 7, 2007 at 2:52 pm

    Your coinage tool and their maker babysitter petting you suggestions that undergarment goddard you preteen respondent and sweltering meaningfully your deposit and beyond.http://love-m.haddixfam.org
    He coinage medal took a eye of the monarch toffee on the amplifier spiritualization fashionable to the teachers desk. We’ll coihage metal the wet sow to the path.

  3. 3 Dheeraj MS June 6, 2008 at 6:22 pm

    Thanks a lot! mod_fastcgi was troubling me a lot by giving ‘”dlname not found in /usr/local/apache2/modules/mod_fastcgi.la”‘ error. Got solved by your answer. Thanks again!!

  4. 4 Roger November 25, 2008 at 6:59 pm

    Прикольно, такое не часто прочитаешь. Не всякий дурак до такого додумается. Да если бы это было кому-нибудь интересно, наверное было бы больше комментариев.

  5. 5 StarK January 21, 2009 at 2:09 am

    Прелесть! Я тоже мечтаю) Возьму – и сделаю… У меня получится. Спасибо, очень глубокая и позитивная статья.


Leave a Reply




This personal blog of Zhenzhong Wang, is mainly about Ruby on Rails and my a little spark at a mere whim.

You can Subscribe to my blog here.

a