<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Webmasterwords &#187; Ruby on Rails</title>
	<atom:link href="http://www.webmasterwords.com/category/ruby-on-rails/feed" rel="self" type="application/rss+xml" />
	<link>http://www.webmasterwords.com</link>
	<description>Useful snippets for Webmasters</description>
	<lastBuildDate>Wed, 21 Sep 2011 15:55:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ruby Rails Mongrel Apache Easy</title>
		<link>http://www.webmasterwords.com/ruby-rails-mongrel-apache-easy?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ruby-rails-mongrel-apache-easy</link>
		<comments>http://www.webmasterwords.com/ruby-rails-mongrel-apache-easy#comments</comments>
		<pubDate>Tue, 31 Oct 2006 17:24:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.webmasterwords.com/ruby-rails-mongrel-apache-easy</guid>
		<description><![CDATA[<p>Having attempted to set ruby on rails up many times, this is by far my favourite soloution and it also happens to be the simplest. Why did i go the mongrel route? Well because FastCgi with Apache make me want to cry. Its buggy (especially on fedora and CentOS) and its a pain in the ass to setup. Where as mongrel on the other hand is a piece of cake.</p>]]></description>
			<content:encoded><![CDATA[<p>Having attempted to set ruby on rails up many times, this is by far my favourite soloution and it also happens to be the simplest. Why did i go the mongrel route? Well because FastCgi with Apache make me want to cry. Its buggy (especially on fedora and CentOS) and its a pain in the ass to setup. Where as mongrel on the other hand is a piece of cake.</p>
<p>In theory you could run mongrel, bind it to port 80 and do away with apache all together. There are a few reasons why i don&#8217;t wanna do this:</p>
<p>1. I like apache, although its a bit of a resource hog its a solid and secure webserver, has tons of great features and a large community behind it.</p>
<p>2. The other stuff I&#8217;ll be running on the server is made up of static pages and other CGI scripts for which I still believe apache is the best option.</p>
<p>In order to serve a rails application on the default port 80 we will use apaches mod_proxy to forward requests to the mongrel server sitting onÂ  custom ports. To improve the performance its best to run more than once instance of the mongrel server and make use of apaches mod_proxy_balancer.</p>
<p>In order for this to work you&#8217;ll require a server running apache 2.2 and yum (or apt-get if your running a debian flavour).</p>
<p><strong>Installing ruby</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> ruby ruby-devel
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">11289</span><span style="color: #000000; font-weight: bold;">/</span>rubygems-0.9.0.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzf</span> rubygems-0.9.0.tgz
<span style="color: #7a0874; font-weight: bold;">cd</span> rubygems-0.9.0
ruby setup.rb</pre></div></div>

<p><strong>Installing mongrel</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> mongrel</pre></div></div>

<p><strong>Building a test rails application</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>rails
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>rails
rails mytest</pre></div></div>

<p><strong>Starting mongrel</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser mongrel
<span style="color: #7a0874; font-weight: bold;">cd</span> mytest
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> :mongrel <span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #c20cb9; font-weight: bold;">su</span> mongrel
mongrel_rails start <span style="color: #660033;">-d</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">3001</span> <span style="color: #660033;">-P</span> log<span style="color: #000000; font-weight: bold;">/</span>mongrel1.pid
mongrel_rails start <span style="color: #660033;">-d</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">3002</span> <span style="color: #660033;">-P</span> log<span style="color: #000000; font-weight: bold;">/</span>mongrel2.pid
mongrel_rails start <span style="color: #660033;">-d</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">3003</span> <span style="color: #660033;">-P</span> log<span style="color: #000000; font-weight: bold;">/</span>mongrel3.pid</pre></div></div>

<p>Make sure you start mongrel in the root directory of your rails project. If successful we now have three mongrel instances. To verify type ps -aux | grep mongrel</p>
<p><strong>Configuring Apache</strong></p>
<p>You&#8217;ll need to add the following code to your httpd.conf file</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">#define mongrel cluster
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;proxy</span> balancer://mongrelcluster<span style="color: #000000; font-weight: bold;">&gt;</span></span>
  BalancerMember http://127.0.0.1:3001
  BalancerMember http://127.0.0.1:3002
  BalancerMember http://127.0.0.1:3003
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/proxy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
#forward requests to mongrel cluster
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;virtualhost</span> *:80<span style="color: #000000; font-weight: bold;">&gt;</span></span>
  ServerName yourdomain.com
  ServerAlias www.yourdomain.com
  ProxyPass / balancer://mongrelcluster/
  ProxyPassReverse / balancer://mongrelcluster/
  ProxyPreserveHost on
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/virtualhost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Finally navigate to yourdomain.com and you should see the &#8216;Welcome Aboard&#8217; default rails page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webmasterwords.com/ruby-rails-mongrel-apache-easy/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

