<?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>Colin Mollenhour&#039;s Technical Blog &#187; Uncategorized</title>
	<atom:link href="http://colin.mollenhour.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://colin.mollenhour.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 31 Jul 2010 06:52:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Right Way to Optimize Apache&#8217;s .htaccess Files</title>
		<link>http://colin.mollenhour.com/2010/06/30/the-right-way-to-optimize-apaches-htaccess-files/</link>
		<comments>http://colin.mollenhour.com/2010/06/30/the-right-way-to-optimize-apaches-htaccess-files/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 23:47:09 +0000</pubDate>
		<dc:creator>colin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://colin.mollenhour.com/?p=127</guid>
		<description><![CDATA[
While researching Magento performance optimizations you have probably already read about how to optimize Apache&#8217;s configuration by moving your configuration directives into the configuration files and out of the .htaccess files. Of course you need root to do this, but assuming you can, there are still very very wrong ways to do this that will [...]]]></description>
			<content:encoded><![CDATA[<p>
While researching Magento performance optimizations you have probably already read about how to optimize Apache&#8217;s configuration by moving your configuration directives into the configuration files and out of the .htaccess files. Of course you need root to do this, but assuming you can, there are still very very wrong ways to do this that will result in no real performance gains, leave gaping security holes, and consume more time than necessary. Read on, a handy script for solving these problems and before and after performance benchmarks to prove the gains are included.
</p>
<p><span id="more-127"></span></p>
<h2>Mistake #1</h2>
<p>If you move your .htaccess contents into the apache config files that is great, but if you forget to disable .htaccess files using <code>AllowOverride None</code> then you&#8217;ve entirely defeated the purpose! The reason this technique can result in performance gains is that it allows the server to ignore the .htaccess files which means fewer directory traversals and fewer file reads with each request. One page load probably results in 20-100 HTTP requests to your Apache server. If you have deeply nested files (all of those cached product images and skin images come to mind) then this results in a lot of disk access. So, you must disable the .htaccess files completely with <code>AllowOverride None</code>! Which brings me to the second major mistake that people can make&#8230;
</p>
<h2>Mistake #2</h2>
<p>
Now that you&#8217;ve disabled .htaccess, guess what? Those .htaccess files had a purpose.. For example, to deny access to your <code>app/etc/local.xml</code> config file!! Great way to expose your database password, let&#8217;s just hope the user is a localhost-only user and you don&#8217;t re-use passwords&#8230; Also, in <code>downloader/.htaccess</code> for example, compression is disabled so that the Magento Connect console can circumvent Apache&#8217;s buffering to display the console output as it occurs. There are others as well. Point is, now you have to move all of these .htaccess files into your apache config. Ugh.. Which brings me to my last point&#8230;
</p>
<h2>Mistake #3</h2>
<p>
It doesn&#8217;t have to be difficult! I&#8217;ve written a bash script (buildhtaccess.sh, see below) which provides you an easy way to benefit from this tweak. In essence the following script will find all of your .htaccess files and compile them into one file which can then be included in your Apache config with only a few lines. If you modify an .htaccess file or a new one is installed by an extension, re-run the script and reload the apache config.
</p>
<h2>Tutorial</h2>
<p>First, download and run the script to generate your .htaccess-combined file.</p>
<pre class="brush: plain;">
$ cd &lt;webroot&gt;
$ wget http://gist.github.com/raw/459311/buildhtaccess.sh
$ bash buildhtaccess.sh
</pre>
</p>
<p>Next, edit your apache config file. Find the <code>&lt;VirtualHost&gt;</code> directive and at the end of it add the following:</p>
<pre class="brush: plain;">
  # Include combined Magento .htaccess files
  &lt;Directory /your_webroot_here&gt;
    AllowOverride None
  &lt;/Directory&gt;
  Include /your_webroot_here/.htaccess-combined
</pre>
</p>
<p>
Lastly, run a graceful reload of the Apache config. A full restart is not necessary. Now you&#8217;re done.
</p>
<h2>Code</h2>
<p>And here is the code for generating the .htaccess-combined file:<br />
<script src="http://gist.github.com/459311.js?file=buildhtaccess.sh"></script>
</p>
<h2>Benchmarks</h2>
<p>For my benchmark I ran &#8220;ab&#8221; (apache bench) since it is quick and easy but admittedly not the best for benchmarking overall site performance. In this case apache bench is going to under state the value of this tweak since one page load in a browser will result in repeated hits on the webserver, all of which will be affected by this optimization. So, I benchmarked on /errors/503.php so that the database is not factored but PHP code is still run. Specifically, I used <code>$ ab -n 1000 -c 20 .../errors/503.php</code>.<br/><br />
Before: <b>~3000 requests per second (3018 max)</b><br/><br />
After: <b>~4600 requests per second (5030 max)</b><br/></p>
<p>That&#8217;s a pretty nice improvement. Unfortunately it is only substantial with fast requests such as the error pages and static files but it should definitely reduce disk contention on a busy server and increase scalability, but probably not do a whole lot for user-experience on a low-contention server.
</p>
<h5>I&#8217;d love to see your results, please post them in the comments!</h5>
]]></content:encoded>
			<wfw:commentRss>http://colin.mollenhour.com/2010/06/30/the-right-way-to-optimize-apaches-htaccess-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The problem with open source software&#8230;</title>
		<link>http://colin.mollenhour.com/2010/05/06/the-problem-with-open-source-software/</link>
		<comments>http://colin.mollenhour.com/2010/05/06/the-problem-with-open-source-software/#comments</comments>
		<pubDate>Fri, 07 May 2010 00:00:36 +0000</pubDate>
		<dc:creator>colin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://colin.mollenhour.com/?p=124</guid>
		<description><![CDATA[I&#8217;ve been using the Mozilla Thunderbird client for several years now and it has served me pretty well. However, one annoyance is that the address book only allows for two email addresses. Thunderbird 3 was released finally in late 2009 and while it was an improvement, it was not ground-breaking (yay for tabs.. err..). Well [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the Mozilla Thunderbird client for several years now and it has served me pretty well. However, one annoyance is that the address book only allows for two email addresses. Thunderbird 3 was released finally in late 2009 and while it was an improvement, it was not ground-breaking (yay for tabs.. err..). Well I finally got fed up with only having two email addresses per contact and started googling in hopes that there was an addon or at least a feature request. Lo and behold there is a bug report for this &#8220;feature&#8221; (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=118665">Allow multiple email addresses</a>). Get this:</p>
<ul>
<li>Status: Assigned</li>
<li>Importance: 75 votes</li>
<li>Reported on: 2002-01-07</li>
<li>Target Milestone: Thunderbird 3.0rc1</li>
</ul>
<p><br/><br />
Looks like it was left out of 3.0rc1 considering I am using 3.0.4. I can&#8217;t believe the ticket is over 8 years old!!</p>
<p>/me looks for a new email client</p>
]]></content:encoded>
			<wfw:commentRss>http://colin.mollenhour.com/2010/05/06/the-problem-with-open-source-software/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My humble website is born&#8230;</title>
		<link>http://colin.mollenhour.com/2008/09/11/my-humble-website-is-born/</link>
		<comments>http://colin.mollenhour.com/2008/09/11/my-humble-website-is-born/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 09:32:33 +0000</pubDate>
		<dc:creator>colin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://colin.mollenhour.com/?p=16</guid>
		<description><![CDATA[FP! Never thought I'd say that..]]></description>
			<content:encoded><![CDATA[<p>Ok, so what kind of web developer doesn&#8217;t have a website? <strong>Me</strong>, but not anymore. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://colin.mollenhour.com/2008/09/11/my-humble-website-is-born/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
