Question: What all should i do to use mod\_fcgid instead of mod\_php on ubuntu and centos. what are the main benefits and difference's between two

Answer: 
On my shared hosting platform I use FastCGI to run PHP through rather than calling it directly. They run PHP via CGI by default rather than as a module so for me it was just a matter of adding the following to my `.htaccess` file:

```
 AddHandler application/myphp .php
 Action application/myphp /cgi-bin/myphp.fcgi

```

Next I had to create the `myphp.fcgi` script in my cgi-bin directory containing:

```
#!/bin/sh

# This ensures PHP doesn't try to run it's own
# process manager.
export PHP_FCGI_CHILDREN=0

# Replace this shell image with a PHP
# image.
exec /path/to/php -c /path/to/my/php.ini

```

This runs flawlessly for me and my hosting environment is running within a cluster of almost a dozen servers behind a hardware load balancer.
cgi = each request starts a process and get's results back to client
fcgi = application (Ruby/Django for example) or interpreter (PHP) stays running and webserver forwards requests and gets responses from it.

FastCGI is almost always faster (for stuff that supports it), however some very ancient stuff (nagios for example) needs cgi.
Only real advantage of cgi is that where there is no traffic scripts cgi application does not use memory, but usually webserver is intelligent enough to shut down FastCGI app that's not used for some time, so that's not a real advantage