Category Archives: Apache

mod_fcgid: can’t apply process slot

It turns out that FastCGI (and I think both for mod_fastcgi and mod_fcgid) doesn’t play well with many of the default Linux setups. fcgid sets up a directory in /var/log/httpd/fcgidsock (mod_fastcgi may be a slightly different directory). The problem is not that the permissions are wrong, but that the permissions of the parent directory are wrong. More to the point, the permissions of the parent directory are made for standard Linux security purposes, not for the purposes of running FastCGI.

The fix is simple. In my case it was a simple chmod 755 /var/log/httpd, which allows Apache to actually read its log directory! Before the change, I was getting “Service Unavailable” with a log error of [warn] mod_fcgid: can’t apply process slot for [dispatch.fcgi full path]. Now it works!

Dynamic Virtualhosting (for subdomains) with apache

Apache provides a very easy method to provide hosting for dynamically created sub-domains with “VirtualScriptAlias” and “VirtualDocumentRoot” syntaxes

Lets say, we have, and you need to dynamically configure, etc. (and not required to manually configure apache or restart), then..

Step 1: Configure wild-card DNS, so that * is a cname to

Step 2: Configure apache. Create a new virtualhost section for *, like:

<VirtualHost *>
ServerAlias *
CustomLog /www/www.logs/ combined
ErrorLog /www/www.logs/
VirtualDocumentRoot /www/
VirtualScriptAlias  /www/

Step 3: Restart apache to activate the new configuration

Step 4: Now, say you need, all that is required is to create /www/ and /www/


Technorati Tags: , , ,

Tomcat UTF8 Characters

If you have issues with tomcat not able to parse/display UTF characters, try adding URIEncoding=”UTF-8″ to your tomcat settings (server.xml).


<Connector port=”8080″ maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″ enableLookups=”false” redirectPort=”8443″ acceptCount=”100″ debug=”0″ connectionTimeout=”20000″ disableUploadTimeout=”true” URIEncoding=”UTF-8″/>

mod_fcgid tips

Make sure you set IPCCommTimeout to at least 45 to allow enough startup
Set DefaultMaxClassProcessCount to 2 unless your benchmarks tell you to
Set IdleTimeout to 3600 or higher since your only have 2 dispatch.fcgi.
Set ProcessLifeTime to a multiple of IdleTimeout.
Set MaxProcessCount > DefaultMaxClassProcessCount so you can use
mod_fcgid for other things than rails.

mod_fcgid religiously kills idle or old processes so keep IdleTimeout
and ProcessLifeTime to high values.

Here is an example ‘starter’ /etc/apache2/mods-enabled/fcgid.conf

AddHandler fcgid-script .fcgi
SocketPath /var/lib/apache2/fcgid/sock
IdleTimeout 3600
ProcessLifeTime 7200
MaxProcessCount 8
DefaultMaxClassProcessCount 2
IPCConnectTimeout 8
IPCCommTimeout 60
DefaultInitEnv RAILS_ENV production

If you have plenty of RAM, then increase DefaultMaxClassProcessCount to
about 2*CPU–assume each instance will eat 20-30MB RAM.

Installing Ruby on Rails with mod_fcgid in Fedora Core 5

In order to make Ruby on Rails work on Fedora Core 5 with apache and mod_fcgid, a mixture of installation from Yum repository and source is required.

Installing Ruby

Install ruby using yum
# yum install ruby

Installing RubyGems

RubyGems is the standard Ruby package manager. It’s similar to apt-get, emerge, and other OS package managers.

  1. Download RubyGems from

  2. Extract, then run “ruby setup.rb”
  3. Install the dependencies required using: gem install rails –include-dependencies

Installing FastCGI

Download and install FCGI from

The final steps

  1. install mysql-devel rpm: yum install mysql-devel
  2. install mysql gem
    gem install mysql — –with-mysql-include=/usr/include/mysql –with-mysql-lib=/usr/lib/mysql

  3. Change database.yml to point to the correct mysql.sock file (say /var/lib/mysql/mysql.sock)
  4. install gem fcgi
    gem install fcgi –source —
    –with-fcgi-include=/usr/local/include –with-fcgi-lib=/usr/local/lib
  5. Configure httpd.conf with the following for your virtualhost:
    AddHandler fcgid-script .fcgi .cgi
    IdleTimeout 3600
    ProcessLifeTime 7200
    MaxProcessCount 8
    DefaultMaxClassProcessCount 2
    IPCConnectTimeout 120
    IPCCommTimeout 60
    DefaultInitEnv RAILS_ENV production
    SocketPath /tmp/fcgid_sock/

Technorati Tags: , , ,