# Apache 2.x: Use fcgid or Mongrel?

**URL:** <https://www.ruby-forum.com/t/apache-2-x-use-fcgid-or-mongrel/77234>\
**Category:** Rails\
**Created:** [March 6, 2006, 12:29pm UTC](https://www.ruby-forum.com/t/apache-2-x-use-fcgid-or-mongrel/77234 "2006-03-06T12:29:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 6, 2006, 12:29pm UTC](https://www.ruby-forum.com/t/apache-2-x-use-fcgid-or-mongrel/77234/1 "2006-03-06T12:29:12Z")

</div>

Hi, There’s lots of stuff going on currently with choices of production  
deployment environments. But I’m not clear on a few things as I need to  
decide on a production setup where Apache is a given.

A recent thread ([FastCGI vs. Simple CGI - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/56590)) seemed to favor  
Apache 2 with mod\_fcgid. And this is supported in articles such as:  
[http://paul.querna.org/journal/articles/2006/01/01/using-mod\_fcgid-for-ruby-on-rails-applications](http://paul.querna.org/journal/articles/2006/01/01/using-mod_fcgid-for-ruby-on-rails-applications)

And then there’s all the excitement about Mongrel.

Question 1. What are the advantages of mongrel over fastcgi?  
[http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/) is not at all clear on this.  
Hint to Zed: How about a “Why use Mongrel” section on the site.

Question 2. Has anybody used Apache 2 with Mongrel? Is this a good idea?  
Any configuration examples available?

By the way, I’m not talking about a high-volume site. But as this is on  
a shared server with other (php) applications, efficiency _is_ an issue.

Thanks,  
Mike.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 7, 2006, 12:58am UTC](https://www.ruby-forum.com/t/apache-2-x-use-fcgid-or-mongrel/77234/2 "2006-03-07T00:58:53Z")

</div>

Greg,

I haven’t done this myself so I might be wrong here, but have you tried  
setting  
ActionController::AbstractRequest.relative\_url\_root = “/dir”  
in your production.rb? It might make things a bit simpler than  
redefining url\_for.

Anyway, feel free to ignore me 🙂

Dan

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 6, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/apache-2-x-use-fcgid-or-mongrel/77234/3 "2006-03-06T15:28:12Z")

</div>

On Mon, Mar 06, 2006 at 12:29:12PM +0100, Mike D wrote:  
} Hi, There’s lots of stuff going on currently with choices of  
production  
} deployment environments. But I’m not clear on a few things as I need  
to  
} decide on a production setup where Apache is a given.  
}  
} A recent thread ([FastCGI vs. Simple CGI - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/56590)) seemed to  
favor  
} Apache 2 with mod\_fcgid. And this is supported in articles such as:  
}  
[http://paul.querna.org/journal/articles/2006/01/01/using-mod\_fcgid-for-ruby-on-rails-applications](http://paul.querna.org/journal/articles/2006/01/01/using-mod_fcgid-for-ruby-on-rails-applications)

I have had great success with Apache2+fcgid, but then I am not dealing  
with  
a production deployment. When I say success, I mean I was able to put up  
a  
Rails app at a non-root path on my existing Apache2 server.

} And then there’s all the excitement about Mongrel.  
}  
} Question 1. What are the advantages of mongrel over fastcgi?  
} [http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/) is not at all clear on this.  
} Hint to Zed: How about a “Why use Mongrel” section on the site.

The primary advantage, if any, would be performance. The only way to  
tell  
if this actually is an advantage is to run tests. You would want to run  
load tests on a staging environment before releasing to production  
anyway.  
If I remember correctly (and there is a strong chance I do not) there is  
something called Watir which is a Ruby web load testing system.

} Question 2. Has anybody used Apache 2 with Mongrel? Is this a good  
idea?  
} Any configuration examples available?

I believe you would set up mongrel to run on a nonstandard port (e.g.  
3000)  
and configure Apache2 to proxy to it. Unsurprisingly you will need  
mod\_proxy loaded. The following should work, substituting as  
appropriate:

ProxyPass /foo/bar [http://localhost:3000/](http://localhost:3000/)  
ProxyPassReverse /foo/bar [http://localhost:3000/](http://localhost:3000/)

You will also need to tell Rails to prepend /foo/bar (substitute your  
path) to  
its links. There may be a better way to do this, but the only way I’ve  
come up  
with is to put the following in your app/controllers/application.rb:

def url\_for(options = {}, \*parameters\_for\_method\_reference)  
normal\_url = super(options, \*parameters\_for\_method\_reference)  
/^http/ =~ normal\_url ? normal\_url : ‘/foo/bar’+normal\_url  
end

Note that it is probably better to put the prepend path string in  
config/environments/production.rb rather than directly in  
application.rb. There  
may be a more elegant solution, but I haven’t come up with it.

} By the way, I’m not talking about a high-volume site. But as this is  
on  
} a shared server with other (php) applications, efficiency _is_ an  
issue.

Since you are more concerned with resource contention than performance,  
I  
suggest that you monitor disk and memory usage during your load tests  
rather than simply reading the numbers from your load testing software.

} Thanks,  
} Mike.  
–Greg

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 7, 2006, 2:00pm UTC](https://www.ruby-forum.com/t/apache-2-x-use-fcgid-or-mongrel/77234/4 "2006-03-07T14:00:09Z")

</div>

On Tue, Mar 07, 2006 at 09:57:04AM +1000, Dan S. wrote:  
} I haven’t done this myself so I might be wrong here, but have you  
tried  
} setting ActionController::AbstractRequest.relative\_url\_root = “/dir”  
in  
} your production.rb? It might make things a bit simpler than redefining  
} url\_for.  
}  
} Anyway, feel free to ignore me 🙂

So there’s bad trolling and there’s good trolling. What I was doing  
there  
was good trolling. I was presenting a working, if inelegant, solution to  
a  
poster’s problem in the hopes that I would be corrected by someone who  
knew  
The Right Way to do it. Now I know, and Knowing Is Half The Battle!

} Dan  
–Greg

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 7, 2006, 1:01am UTC](https://www.ruby-forum.com/t/apache-2-x-use-fcgid-or-mongrel/77234/5 "2006-03-07T01:01:55Z")

</div>

Haha, just noticed Nicholas S. answered this the same way in the  
other thread 🙂
