<?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; bash</title>
	<atom:link href="http://colin.mollenhour.com/tag/bash/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>Module Manager Update, now on Google Code!</title>
		<link>http://colin.mollenhour.com/2010/01/31/module-manager-update/</link>
		<comments>http://colin.mollenhour.com/2010/01/31/module-manager-update/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 04:15:40 +0000</pubDate>
		<dc:creator>colin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://colin.mollenhour.com/?p=109</guid>
		<description><![CDATA[
I recently updated Module Manager (first post) to support nested modules and renamed the .modman definitions file to simply modman for easier editing in IDEs. To top it off I am officially releasing it to the public under the Apache License 2.0 so that you may start using it in your own projects.

Additionally, Module Manager [...]]]></description>
			<content:encoded><![CDATA[<p>
I recently updated Module Manager (<a href="http://colin.mollenhour.com/2009/10/17/module-manager-for-when-svnexternals-just-doesnt-cut-it/">first post</a>) to support nested modules and renamed the <code>.modman</code> definitions file to simply <code>modman</code> for easier editing in IDEs. To top it off I am officially releasing it to the public under the Apache License 2.0 so that you may start using it in your own projects.</p>
<p>
Additionally, <span style="font-size:120%; font-weight:bold;"><a href="http://code.google.com/p/module-manager/">Module Manager</a></span> now has it&#8217;s own home on Google Code so check it out! (pun intended)
</p>
<p>
Here is an example of the new <b>nested modules</b> feature:
</p>
<pre class="brush: plain;">
# My template files
skin               skin/frontend/my/default
design             app/design/frontend/my/default

# Import Colin_HotDealz module
@import            modules/Colin_HotDealz
</pre>
]]></content:encoded>
			<wfw:commentRss>http://colin.mollenhour.com/2010/01/31/module-manager-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Module Manager &#8211; for when svn:externals just doesn&#8217;t cut it.</title>
		<link>http://colin.mollenhour.com/2009/10/17/module-manager-for-when-svnexternals-just-doesnt-cut-it/</link>
		<comments>http://colin.mollenhour.com/2009/10/17/module-manager-for-when-svnexternals-just-doesnt-cut-it/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 05:38:16 +0000</pubDate>
		<dc:creator>colin</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://colin.mollenhour.com/?p=96</guid>
		<description><![CDATA[
Update 1/30/2010:
Added nested modules, renamed .modman file to modman, released under Apache License 2.0, and hosted on Google Code.

This project was inspired by my recent Magento development work so I&#8217;m not sure how much application it has outside of that, but if you&#8217;ve ever wanted to use svn:externals with individual files (you can&#8217;t btw) then [...]]]></description>
			<content:encoded><![CDATA[<hr/>
<p><span style="font-size:120%; font-weight:bold"><a href="http://colin.mollenhour.com/2010/01/31/module-manager-update/">Update 1/30/2010:</a></span><br />
Added nested modules, renamed .modman file to modman, released under Apache License 2.0, and hosted on Google Code.</p>
<hr/>
<p>This project was inspired by my recent Magento development work so I&#8217;m not sure how much application it has outside of that, but if you&#8217;ve ever wanted to use svn:externals with individual files (you can&#8217;t btw) then this is the next best thing (and therefore the best thing). Perhaps some other VCS supports this functionality natively , if you know of it please clue me in. I&#8217;ve used git and bazaar but still like the simplicity of subversion for small, non-distributed projects.</p>
<p>Magento&#8217;s source code is split among several different groups of files: code, design, locale, skin, libs, etc (as in config), etc.. (as in etcetera)<br />
You really cannot avoid ever having to mix a file in here or there which means svn:externals won&#8217;t cut it. Besides, svn:externals won&#8217;t let you make one commit from all of your externals so to commit your changes you have to do it once for each folder which makes your commit history nearly useless. Enter &#8220;modman&#8221;, my Magento module manager. While it could be used for deployment it is primarily geared towards developers. Here is how it works:</p>
<p><span id="more-96"></span></p>
<p>Create a branch and put your source code in it. Now create a &#8220;.modman&#8221; file within the root of the branch. In this file you define (much like svn:externals) a path within your repository and the path that it should map to. Here is an example (with a fictitious module named &#8220;HotDealz&#8221;:</p>
<pre class="brush: plain;">
code   app/code/local/Colin/HotDealz
template   app/design/frontend/default/default/template/hotdealz
hotdealz.xml   app/design/frontend/default/default/layout/hotdealz.xml
images   skin/frontend/default/default/images/hotdealz
HotDealz.csv   app/locale/en_US/Colin_HotDealz.csz
</pre>
<p>As you can see, very similar to svn:externals only with individual file support which is handy for things like locale files that can&#8217;t go in subdirectories.</p>
<h2>How It Works</h2>
<p>Usage is similar to regular command line usage of subversion. The &#8220;modman&#8221; script provides a wrapper around svn which checks the code out in a .modman directory at the root of your project then reads the .modman file and creates symbolic links as necessary so that your source code is actually all contained within one directory and your webserver accesses the files where they are supposed to be. No svn:externals definitions are used. Obviously this requires a few things:</p>
<ol>
<li>bash</li>
<li>a webserver that is configured to FollowSymLinks</li>
</ol>
<p><br/></p>
<p>
If you do web development on Windows, you may be thinking, &#8220;What about Windows support!?&#8221;. Well, you have a few options:
</p>
<ul>
<li>Do your development inside a VirtualBox instance of Linux and share the drive to Windows for editing on your IDE (recommended).</li>
<li>Try to configure cygwin to work (untested, not recommended).</li>
</ul>
<p><br/></p>
<p>
I chose the former long before I wrote this script since the servers for my projects are all Linux-based and doing development on WAMP when your project runs on L*MP is silly. You can actually still use TortoiseSVN by simply opening the .modman directory from explorer so really after the initial checkout you do not need to continue to use the script except for when adding new definitions to the .modman file.
</p>
<h2>Sample Usage</h2>
<p>Here are some typical commands used with modman:</p>
<pre class="brush: plain;">
$ modman --help
$ modman init
$ modman hotdealz checkout &quot;svn url here&quot;
$ modman hotdealz status (can be run from any directory within the project root)
$ modman hotdealz commit
$ modman hotdealz update
$ modman hotdealz add Colin_HotDealz.xml app/etc/modules/HotDealz.xml
etc...
</pre>
<p>Most commonly used svn commands are passed through to svn for convenience but for advanced work you can just cd to the .modman directory or use TortoiseSVN or your IDE&#8217;s integrated subversion tools (I use Netbeans).</p>
<h3>Documentation</h3>
<pre>
----------------------
Magento Module Manager
----------------------
Usage: modman &lt;module&gt; &lt;action&gt; [svn args]
Supported global actions (no module specified):
  init           initialize the current directory as the modman root (no module name)
  update-all     update all modules that are currently checked out

Supported actions: (all svn commands support additional arguments)
  checkout       checkout a new modman compatible module
  export         export a modman compatible module (does real copy instead of symlinks)
  update [...]   update module
  add &lt;svn_path&gt; &lt;real_path&gt;   add a file/dir to the .modman file and working copy
  delete &lt;svn_path&gt;   remove a file/dir from the .modman file and working copy
  status         show status of entire module
  diff [...]     run svn diff on module
  commit [...]   commit changes to module
  info           show the module's working copy path and run svn info on working copy
  list           list the definitions in the .modman file

The repository should contain a file called &quot;.modman&quot; which defines which files
go where relative to the directory where modman was initialized.

If additional arguments are given to commands such as commit, paths
should be relative to the svn root.

---- Start example .modman file ----
# Comments are supported, begin a line with a hash
code                   app/code/local/My/Module/
design                 app/design/frontend/default/default/mymodule/
locale/My_Module.xml   app/locale/en_US/My_Module.xml
My_Module.xml          app/etc/modules/My_Module.xml
---- End example .modman file ----

Author:
Colin Mollenhour

http://colin.mollenhour.com/

colin@mollenhour.com
</pre>
<h3><a href="http://gist.github.com/212246">View Source</a></h3>
<h3><a href="http://gist.github.com/raw/212246/1b301e9aeb9bf83730008ccdb6ecb18651f073f5/modman">Download</a></h3>
<p>Leave a comment if you use it!</p>
]]></content:encoded>
			<wfw:commentRss>http://colin.mollenhour.com/2009/10/17/module-manager-for-when-svnexternals-just-doesnt-cut-it/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
