<?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"
	>

<channel>
	<title>Mikenbob.com</title>
	<atom:link href="http://www.mikenbob.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikenbob.com</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Wed, 16 Jul 2008 15:29:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Apache &#038; Mongrel - Serving the Future of Development</title>
		<link>http://www.mikenbob.com/2007/01/apache-and-mongrel/</link>
		<comments>http://www.mikenbob.com/2007/01/apache-and-mongrel/#comments</comments>
		<pubDate>Mon, 01 Jan 2007 14:00:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Helps and Walkthroughs]]></category>

		<category><![CDATA[Linux Hints]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mikenbob.com/?p=36</guid>
		<description><![CDATA[My current setup is putting Mongrel behind my Apache server
running mod_proxy_balancer. Why? I am not going to try and convince you, other than saying it&#8217;s the best I&#8217;ve found (so far). FastCGI crashes too much. The best information can be found at Mongrel&#8217;s site.
Introducing Apache + Mongrel
First, be sure you have a working installation of [...]]]></description>
			<content:encoded><![CDATA[<p>My current setup is putting Mongrel behind my <a href="http://httpd.apache.org/" target="_blank">Apache</a> server<br />
running mod_proxy_balancer. <em>Why?</em> I am not going to try and convince you, other than saying it&#8217;s the best I&#8217;ve found (so far). FastCGI crashes too much. The best information can be found at <a href="http://mongrel.rubyforge.org/" target="_blank">Mongrel&#8217;s</a> site.</p>
<h3>Introducing Apache + Mongrel</h3>
<p>First, be sure you have a working installation of Apache, a working rails application. If not,<br />
go to that <a href="/index.php?p=27">walkthrough</a>. If so, feel free to read on!</p>
<p>Because you have already taken a look at Mongrel&#8217;s website, you already know that it is NOT the greatest at managing large amounts<br />
of requests. From their <a href="http://mongrel.rubyforge.org/faq.html">FAQ</a>:</p>
<blockquote cite="http://mongrel.rubyforge.org/faq.html"><p>Q: Is it multi-threaded or can it handle concurrent requests?<br />
A: Mongrel uses one thread per request,<br />
but it will start closing connections when it gets &#8220;overloaded&#8221;&#8230;</p></blockquote>
<p>Because of this, and the fact that Apache is a much better overall web-server, we will create a cluster of mongrel servers,<br />
and have apache searve them to mongrel through the mod_proxy_balancer module. (so be sure to have it installed and configured!)</p>
<h3>Install Mongrel and Mongel_Cluster</h3>
<p>Let&#8217;s use gem to install mongrel and mongrel_cluster</p>
<pre><kbd>$  gem install mongrel mongrel_cluster --include-dependencies</kbd></pre>
<h3>Creating a Mongrel Cluster</h3>
<p>mongrel_cluster includes scritps to automatically set up a cluster of servers.</p>
<pre><kbd style="overflow: auto; height: 60px;">$  mongrel_rails cluster::configure -e production -p 8000 -N 3 -c /var/www/apps/myapp -a 127.0.0.1 --user mongrel --group mongrel
Writing configuration file to config/mongrel_cluster.yml.</kbd></pre>
<p>Now a configuration file has been created in the RAILS_ROOT/config directory called &#8216;mongrel_cluster.yml&#8217;. Try it out with</p>
<pre><kbd>$  mongrel_rails cluster::start
Starting 3 Mongrel servers...</kbd></pre>
<p>I have a startup script installed to start my mongrel servers at boot. To make that happen simply&#8230;</p>
<pre><kbd>$  mkdir /etc/mongrel_cluster
$  ln -s /var/www/apps/myapp/config/mongrel_cluster.yml /etc/mongrel_cluster/myapp.yml
$  cp /path/to/mongrel_cluster_gem/resources/mongrel_cluster /etc/init.d/
$  chmod +x /etc/init.d/mongrel_cluster</kbd></pre>
<p>And add the script to the system V init</p>
<pre><kbd>$  /usr/sbin/update-rc.d -f mongrel_cluster defaults</kbd></pre>
<p>According to the mongrel site&#8230;</p>
<blockquote cite="http://mongrel.rubyforge.org/docs/mongrel_cluster.html"><p>NOTE At this point there are a few issues with this init script that only apply under certain circumstances. Those issues include:</p>
<ul>
<li>Shebang line - The init script uses #!/usr/bin/env ruby to find the appropriate interpreter. Some distribution installs of ruby only give you a /usr/bin/ruby1.8. You may change the shebang line or simply create a symbolic link from /usr/bin/ruby1.8 to /usr/bin/ruby3.</li>
<li>mongrel_cluster_ctl location - If you have installed your gems in /usr/local/ you may find that the init script can not find mongrel_cluster_ctl. To resolve this, you can symbolically link /usr/local/bin/mongrel_cluster_ctl into /usr/bin/</li>
</ul>
</blockquote>
<h3>Apache Modules</h3>
<p>There are a few required modules to have installed or compiled into your apache configuration. Debian, again, makes this quite easy<br />
with the a2enmod command</p>
<pre><kbd>$   a2enmod proxy
Module proxy installed; run /etc/init.d/apache2 force-reload to enable.
$   a2enmod proxy_http
Module proxy_http installed; run /etc/init.d/apache2 force-reload to enable.
$   a2enmod proxy_balancer
Module proxy_balancer installed; run /etc/init.d/apache2 force-reload to enable.
$   a2enmod rewrite
Module rewrite installed; run /etc/init.d/apache2 force-reload to enable.
$   a2enmod deflate
Module deflate installed; run /etc/init.d/apache2 force-reload to enable.
$   # Now reload your Apache Configuration
$   /etc/init.d/apache2 reload</kbd></pre>
<p>You may get messages like the ones below. It&#8217;s okay.</p>
<pre><code>This module is already enabled!
Enabling cache as a dependency
</code></pre>
<h3>Apache VHost Configuration</h3>
<p>The cluster setup is just the first step (and I should add, the easiest step). Here&#8217;s the fun stuff. Getting Apache to send what<br />
it should to that cluster, and what it should NOT. There is no reason to send images, css files, javascript files, and any other<br />
static file to mongrel. It should only send Ruby on Rails requests. Most of this was learned from the<br />
<a href="http://mongrel.rubyforge.org/docs/apache.html">Mongrel Apache</a> docs, but there is a lot that I did myself. For example,<br />
you can still run PHP sites with this setup.</p>
<p>First, I will show you some highlites. Then, below, you can see the entire vhost file<br />
Again, I am assuming Debian, so each VHost file is it&#8217;s own entity. You can make changes where needed.</p>
<pre><code>&lt;Proxy balancer://mongrel_cluster_myapp&gt;
        BalancerMember http://127.0.0.1:8000
        BalancerMember http://127.0.0.1:8001
&lt;/Proxy&gt;</code></pre>
<p>You can see that the proxy balancer has a name. That name is <em>mongrel_cluster_myapp</em>. A frequent mistake is creating<br />
two balancers (for two different rails apps) that have the same balancer name. BE CAREFUL! You could spend hours trying to<br />
trouble shoot this!</p>
<pre><code>DocumentRoot /var/www/seminar/public
&lt;Directory /var/www/apps/myapp/public&gt;
    ... dir options here
&lt;/Directory&gt;</code></pre>
<p>The DocumentRoot and Home Directory need to be in the <em>public</em> folder.</p>
<pre><code style="overflow: auto; height: 250px;">RewriteEngine On

## Add trailing slash to directories
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [QSA,R]

## If it's not a file, but index.html exists under that direcory, use that
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [QSA]

## If it's not a file, but index.php exists under that direcory, use that
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.php -f
RewriteRule ^(.*)$ $1/index.php [QSA]

## Rewrite to check for Rails cached page, VERIFY YOUR CLUSTER NAME!!
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [QSA]
        # Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster_myapp%{REQUEST_URI} [P,QSA,L]

## Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/css
# ... text/xml application/xml application/xhtml+xml text/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html</code></pre>
<p>And there is the magic! Using Apache Rewrite rules, you can check for .html and .php index files and use those, check<br />
for rails cache files, and finally, if it&#8217;s not a static file (image, css, javascript, etc.) pass the request to the Mongrel<br />
Cluster. Because it&#8217;s checking for actual files, be sure to put your php files in the public folder. That way, it can see<br />
the file actually exists.</p>
<p><strong>Entire VHost File</strong></p>
<pre><code style="overflow: auto; height: 250px;">&lt;Proxy balancer://mongrel_cluster_myapp&gt;
        BalancerMember http://127.0.0.1:8000
        BalancerMember http://127.0.0.1:8001
&lt;/Proxy&gt;

NameVirtualHost *:80
&lt;VirtualHost *:80&gt;

        ServerName myapp.example.com
        DocumentRoot /var/www/apps/myapp/public

        #### HOME DIRECTORY ####
        &lt;Directory /var/www/apps/myapp/public&gt;
                Options FollowSymLinks
                AllowOverride all
                Order allow,deny
                Allow from all
        &lt;/Directory&gt;
        ### END HOME ###

        ### REWRITES ###
        RewriteEngine On

        # Uncomment for rewrite debugging
        #RewriteLog /var/www/apps/myapp/myapp_rewrite_log
        #RewriteLogLevel 9

        ## Add trailing slash to directories
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
        RewriteRule ^(.+[^/])$ $1/ [QSA,R]

        ## If it's not a file, but index.html exists under that direcory, use that
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.html -f
        RewriteRule ^(.*)$ $1/index.html [QSA]

        ## If it's not a file, but index.php exists under that direcory, use that
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.php -f
        RewriteRule ^(.*)$ $1/index.php [QSA]

        # Rewrite to check for Rails cached page
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
        RewriteRule ^([^.]+)$ $1.html [QSA]

        # Redirect all non-static requests to cluster
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
        RewriteRule ^/(.*)$ balancer://mongrel_cluster_myapp%{REQUEST_URI} [P,QSA,L]

        # Deflate
        AddOutputFilterByType DEFLATE text/html text/plain text/css
        # ... text/xml application/xml application/xhtml+xml text/javascript
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

        # this not only blocks access to .svn directories, but makes it appear
        # as though they aren't even there, not just that they are forbidden
        &lt;DirectoryMatch "^/.*/\.svn/"&gt;
                ErrorDocument 403 /404.html
                Order allow,deny
                Deny from all
                Satisfy All
        &lt;/DirectoryMatch&gt;

        ### SERVER SETTINGS ###
        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

&lt;/VirtualHost&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mikenbob.com/2007/01/apache-and-mongrel/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby on Rails Installation - Linux</title>
		<link>http://www.mikenbob.com/2007/01/ruby-on-rails-installation-linux/</link>
		<comments>http://www.mikenbob.com/2007/01/ruby-on-rails-installation-linux/#comments</comments>
		<pubDate>Mon, 01 Jan 2007 14:00:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Helps and Walkthroughs]]></category>

		<category><![CDATA[Linux Hints]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mikenbob.com/?p=27</guid>
		<description><![CDATA[My current web-development method of choice is Ruby on Rails. Here, I will show you how
to install it when running the latest Debian server.
Initial Installation
I am running a Debian box currently. I had many problems trying to install and run rails without errors. The following is what
I did to make it work. These steps assume [...]]]></description>
			<content:encoded><![CDATA[<p>My current web-development method of choice is <a href="http://www.rubyonrails.org/">Ruby on Rails.</a> Here, I will show you how<br />
to install it when running the latest Debian server.</p>
<h3>Initial Installation</h3>
<p>I am running a Debian box currently. I had many problems trying to install and run rails without errors. The following is what<br />
I did to make it work. These steps assume root access. If you don&#8217;t have it, try sudo.</p>
<p>NOTICE: I take no responsibility for you messing up your systems. Please back up everything before attempting to follow these<br />
steps. I worked for me!</p>
<h3>Prep for installation</h3>
<p>I had to have build-essintial installed. It wasn&#8217;t included in my initial install</p>
<pre><kbd>$  apt-get install build-essential</kbd></pre>
<h3>Install Ruby</h3>
<p>apt-get works for these:</p>
<pre><kbd>$  apt-get install ruby libruby1.8 ruby1.8 ruby1.8-dev</kbd></pre>
<h3>Prep for Gems</h3>
<p>Not sure why, but I couldn&#8217;t install gems without these:</p>
<pre><kbd>$  apt-get install irb1.8 libgems-ruby1.8 libopenssl-ruby1.8 libreadline-ruby1.8 rdoc1.8</kbd></pre>
<h3>Install Gems</h3>
<p>If using Debian, you can install rubygems with apt-get. Run this command, then skip to update.</p>
<pre><kbd>$  apt-get install rubygems</kbd></pre>
<p>Not on Debian? Most people would be able to start right here! I liked the actual install of gems from a file. I&#8217;m not sure if apt-get gems works or not.</p>
<pre><kbd>$  # Download/Extract RubyGems @ <a style="color:#fff;" href="http://rubyforge.org/frs/?group_id=126" target="_blank">http://rubyforge.org/frs/?group_id=126</a>

$  wget http://rubyforge.org/frs/download.php/????/rubygems-X.X.X.tgz # Please go to the site for the actual download
$  tar xzvf rubygems-X.X.X.tgz
$  cd rubygems-X.X.X.tgz
$  ruby setup.rb</kbd></pre>
<h3>Update</h3>
<p>It&#8217;s a good time to update your system configuration now:</p>
<pre><kbd>$  gem update
$  gem update --system</kbd></pre>
<h3>Install Rails</h3>
<p>Now, install Rails from Gem</p>
<pre><kbd>$  #gem install -v=1.2.2 rails --include-dependencies # If you want a particular version...
$  gem install rails --include-dependencies</kbd></pre>
<h3>Next step&#8230; Making Apache work with Mongrel</h3>
<p><a href="/index.php?p=36">Apache &amp; Mongrel - Serving the Future of Development</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikenbob.com/2007/01/ruby-on-rails-installation-linux/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
