<?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>Straylight Run &#187; apache</title> <atom:link href="http://blog.straylightrun.net/tag/apache/feed/" rel="self" type="application/rss+xml" /><link>http://blog.straylightrun.net</link> <description>Software, Technology, PHP</description> <lastBuildDate>Mon, 07 Nov 2011 19:26:59 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>HTTP Keep-Alive</title><link>http://blog.straylightrun.net/2010/09/10/http-keep-alive/</link> <comments>http://blog.straylightrun.net/2010/09/10/http-keep-alive/#comments</comments> <pubDate>Fri, 10 Sep 2010 21:13:51 +0000</pubDate> <dc:creator>gerard</dc:creator> <category><![CDATA[Performance]]></category> <category><![CDATA[Sysadmin]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[config]]></category> <category><![CDATA[headers]]></category> <category><![CDATA[http]]></category> <category><![CDATA[keep alive]]></category> <category><![CDATA[optimization]]></category> <category><![CDATA[subdomains]]></category> <category><![CDATA[virtual host]]></category> <guid
isPermaLink="false">http://blog.straylightrun.net/2010/09/10/http-keep-alive/</guid> <description><![CDATA[Like most people, I did not know much about HTTP Keep-Alive headers other than that they could be very bad if used incorrectly. So I’ve kept them off, which is the default. But I ran across this blog post which explains the HTTP Keep-Alive, including its benefits and potential pitfalls pretty clearly. It’s all pretty [...]]]></description> <content:encoded><![CDATA[<p>Like most people, I did not know much about <a
href="http://httpd.apache.org/docs/2.2/mod/core.html#keepalive">HTTP Keep-Alive headers</a> other than that they could be <em>very </em>bad if used incorrectly. So I’ve kept them off, which is the default. But I ran across this blog post which <a
href="http://virtualthreads.blogspot.com/2006/01/tuning-apache-part-1.html">explains the HTTP Keep-Alive</a>, including its benefits and potential pitfalls pretty clearly.</p><p>It’s all pretty simple really. There is an overhead to opening and closing TCP connections. To alleviate this, Apache can agree to provide persistent connections by sending HTTP Keep-Alive headers. Then the browser can open a single connection to download multiple resources. But Apache won’t know when the browser is done downloading, so it simply keeps the connection open according to a Keep-Alive timeout, which is set to 15 seconds by default. The problem is the machine can only keep so many simultaneous requests open due to physical limitations (e.g. RAM, CPU, etc.) And 15 seconds is a <em>long</em> time.</p><p>To allow browsers to gain some parallelism on downloading files, without keeping persistent connections open too long, the Keep-Alive timeout value should be set to something very low, e.g. 2 seconds.</p><p>I’ve done this for <em>static content only</em>. Why only static content? It doesn’t really make much sense for the main page source itself since that’s the page the user wants to view.</p><p>I’ve <a
href="http://blog.straylightrun.net/2008/11/16/slides-from-phpworks-2008-part-2/">mentioned before</a> that by serving all static content on dedicated subdomains, we indirectly get the benefit of being able to optimize just those subdomains. So far, this meant:</p><ol><li>disabling <code>.htaccess </code>files</li><li>setting a far-future Expires: header</li><li>avoiding setting cookies on the subdomain</li></ol><p>Now we can add to the list: enabling HTTP Keep-Alive headers. The <code>VirtualHost </code>block might look like this now:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>VirtualHost <span style="color: #339933;">*:</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">&gt;</span>
    ServerName      static0<span style="color: #339933;">.</span>yourdomain<span style="color: #339933;">.</span>com
    ServerAlias     static1<span style="color: #339933;">.</span>yourdomain<span style="color: #339933;">.</span>com
    ServerAlias     static2<span style="color: #339933;">.</span>yourdomain<span style="color: #339933;">.</span>com
    ServerAlias     static3<span style="color: #339933;">.</span>yourdomain<span style="color: #339933;">.</span>com
    DocumentRoot    <span style="color: #339933;">/</span><span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>vhosts<span style="color: #339933;">/</span>yourdomain<span style="color: #339933;">.</span>com
    KeepAlive On
    KeepAliveTimeout <span style="color: #cc66cc;">2</span>
    <span style="color: #339933;">&lt;</span>Directory <span style="color: #0000ff;">&quot;/var/www/vhosts/yourdomain.com&quot;</span><span style="color: #339933;">&gt;</span>
        AllowOverride None
        ExpiresActive On
        ExpiresByType text<span style="color: #339933;">/</span>css <span style="color: #0000ff;">&quot;access plus 1 year&quot;</span>
        ExpiresByType application<span style="color: #339933;">/</span>x<span style="color: #339933;">-</span>javascript <span style="color: #0000ff;">&quot;access plus 1 year&quot;</span>
        ExpiresByType image<span style="color: #339933;">/</span>jpeg <span style="color: #0000ff;">&quot;access plus 1 year&quot;</span>
        ExpiresByType image<span style="color: #339933;">/</span>gif <span style="color: #0000ff;">&quot;access plus 1 year&quot;</span>
        ExpiresByType image<span style="color: #339933;">/</span>png <span style="color: #0000ff;">&quot;access plus 1 year&quot;</span>
    <span style="color: #339933;">&lt;/</span>Directory<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>VirtualHost<span style="color: #339933;">&gt;</span></pre></div></div> ]]></content:encoded> <wfw:commentRss>http://blog.straylightrun.net/2010/09/10/http-keep-alive/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Throw Away Your Hosts File! Developing Locally With BIND</title><link>http://blog.straylightrun.net/2010/05/10/throw-away-your-hosts-file-developing-locally-with-bind/</link> <comments>http://blog.straylightrun.net/2010/05/10/throw-away-your-hosts-file-developing-locally-with-bind/#comments</comments> <pubDate>Tue, 11 May 2010 03:36:57 +0000</pubDate> <dc:creator>gerard</dc:creator> <category><![CDATA[Sysadmin]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[bind]]></category> <category><![CDATA[dns]]></category> <category><![CDATA[ipconfig]]></category> <category><![CDATA[nameserver]]></category> <category><![CDATA[virtual host]]></category> <guid
isPermaLink="false">http://blog.straylightrun.net/2010/05/10/throw-away-your-hosts-file-developing-locally-with-bind/</guid> <description><![CDATA[Note the following applies to Windows Vista, but is probably easier on MacOS/Linux. Is your hosts file becoming monstrous?  Do you have an alias or shortcut to your hosts file because you edit it so often?  Tired of manually adding every subdomain and domain you work on? I was too when I thought there must [...]]]></description> <content:encoded><![CDATA[<blockquote><p>Note the following applies to Windows Vista, but is probably easier on MacOS/Linux.</p></blockquote><p>Is your <code>hosts </code>file becoming monstrous?  Do you have an alias or shortcut to your <code>hosts </code>file because you edit it so often?  Tired of manually adding every subdomain and domain you work on?</p><p>I was too when I thought <em>there must be a better way</em>.  And there was.</p><p>The general idea is this: by installing a local DNS nameserver in BIND, we can set up local development domains that look like regular domains on the internet. For real domains, we’ll just forward the requests on to a real nameserver.  This gives us a couple more benefits: 1) we can use the local nameserver as a caching nameserver to speed up DNS queries (in theory, I have not actually done this), and 2) we can choose to use any DNS service we wish, i.e. <a
href="http://www.opendns.com/">OpenDNS</a>, or <a
href="http://code.google.com/speed/public-dns/">Google DNS</a>.</p><p>Here are the steps.</p><ol><li>Follow these instructions on <a
href="http://alex.charrett.com/bind-on-windows-mainmenu-3">installing and configuring BIND</a> and configuring a zone for your local domain.<ol><li>I installed BIND to <code>C:\Windows\system32\dns</code>.</li><li>Here is my <code>named.conf </code>in its entirety.<br/><br/><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">options {
    directory &quot;;c:\windows\system32\dns\zones&quot;;
    allow-transfer { none; };
    forward only;
    forwarders {
        //208.67.222.222; // OpenDNS
        //208.67.220.220;
        8.8.8.8; // Google DNS
        8.8.4.4;
    };
    query-source address * port 53;
};
&nbsp;
/*
logging {
    channel queries_log {
        file &quot;c:\windows\system32\dns\var\queries.log&quot;;
        print-severity yes;
        print-time yes;
    };
    category queries { queries_log ; };
};
*/
&nbsp;
zone &quot;work.local&quot; IN {
    type master;
    file &quot;work.local.txt&quot;;
};
&nbsp;
key &quot;rndc-key&quot; {
    algorithm hmac-md5;
    secret &quot;xxxxxxxxxxxxxxxxxxxxxxxx&quot;;
};
&nbsp;
controls {
    inet 127.0.0.1 port 953
        allow { 127.0.0.1; } keys { &quot;rndc-key&quot;; };
};</pre></div></div></li><li>I created a zone file for my development domain work.local following this <a
href="http://www.xenocafe.com/tutorials/dns_linux/redhat/dns_linux_redhat-part2.php">zone file example</a>. Here is the zone file in its entirety.  Note the <code>CNAME </code>wildcard record.<br/><br/><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">$TTL 86400
@	IN SOA	ns1.work.local.	admin.work.local. (
			2008102403
			10800
			3600
			604800
			86400 )
&nbsp;
@		NS	ns1.work.local.
&nbsp;
	IN A	127.0.0.1
ns1	IN A	127.0.0.1
www	IN A	127.0.0.1
*	IN CNAME	www</pre></div></div></li></ol></li><li>Start or restart the BIND service.</li><li>Configure you network connection to use 127.0.0.1 as your primary nameserver, instead of DHCP.  My IPv4 properties look like this:<a
href="http://blog.straylightrun.net/wp-content/uploads/2010/05/ipconfig.jpg"><br/><br/><img
style="display: inline; border: 0px;" title="Set DNS nameserver to 127.0.0.1" src="http://blog.straylightrun.net/wp-content/uploads/2010/05/ipconfig_thumb.jpg" border="0" alt="Set DNS nameserver to 127.0.0.1" width="499" height="581" /></a></li><li>Flush the Windows DNS cache by running:<br/><br/><div
class="wp_syntax"><div
class="code"><pre class="dos" style="font-family:monospace;">C:\<span style="color: #33cc33;">&gt;</span> ipconfig /flushdns</pre></div></div></li><li>Test BIND by pinging <code>www.work.local</code>.  If you have errors, you can uncomment the logging block in <code>named.conf</code>.</li><li>Once that is working, create a <code>VirtualHost </code>in Apache for your development domain.  Thanks to <a
href="http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html#virtualdocumentroot"><code>VirtualDocumentRoot</code></a>, we can map any number of subdomains to project roots.  Here is my <code>VirtualHost </code>block.<br/><br/><div
class="wp_syntax"><div
class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span>  127.0.0.1&gt;
    <span style="color: #00007f;">ServerName</span> www.work.local
    <span style="color: #00007f;">ServerAlias</span> *.work.local
    <span style="color: #00007f;">VirtualDocumentRoot</span> <span style="color: #7f007f;">&quot;C:/_work/%1&quot;</span>
    &lt;<span style="color: #000000; font-weight:bold;">Directory</span>  C:/_work&gt;
        <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span> <span style="color: #0000ff;">Includes</span> ExecCGI
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span>
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div></li><li>Start or restart Apache.</li><li>Create a directory in <code>C:\_work</code>, for example, <code>C:\_work\awesomeapp</code>.  Create a test index.html file in that directory.</li><li>You should now be able to go to <a
href="http://awesomeapp.work.local">http://awesomeapp.work.local</a> in your browser and see your index.html file!</li></ol><p>Now, you should be able to repeat step 8 for any new website you create!  No editing of <code>hosts </code>files, no bouncing the webserver!  Just create the project directory and it’s immediately available.</p><p>One other important note: Firefox has its own DNS cache independent of the OS.  For sanity, restarting Firefox resets its DNS cache. You can also <a
href="http://www.techiecorner.com/225/how-to-disable-firefox-dns-cache/">permanently disable DNS caching in Firefox</a>.</p> ]]></content:encoded> <wfw:commentRss>http://blog.straylightrun.net/2010/05/10/throw-away-your-hosts-file-developing-locally-with-bind/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Clearing The Linux Buffer Cache</title><link>http://blog.straylightrun.net/2009/12/03/clearing-the-linux-buffer-cache/</link> <comments>http://blog.straylightrun.net/2009/12/03/clearing-the-linux-buffer-cache/#comments</comments> <pubDate>Thu, 03 Dec 2009 19:22:45 +0000</pubDate> <dc:creator>gerard</dc:creator> <category><![CDATA[Performance]]></category> <category><![CDATA[Sysadmin]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[buffer cache]]></category> <category><![CDATA[disk]]></category> <category><![CDATA[logs]]></category> <category><![CDATA[mysql]]></category> <guid
isPermaLink="false">http://blog.straylightrun.net/2009/12/03/clearing-the-linux-buffer-cache/</guid> <description><![CDATA[According to these Munin memory graphs, the large orange area is the OS buffer cache – a buffer the OS uses to cache plain ol’ file data on disk.&#160; The graph below shows one of our web servers after we upgraded its memory.&#160; It makes sense that most of the memory not used by apps [...]]]></description> <content:encoded><![CDATA[<p>According to these <a
href="http://munin.projects.linpro.no/">Munin</a> memory graphs, the large orange area is the OS buffer cache – a buffer the OS uses to cache plain ol’ file data on disk.&#160; The graph below shows one of our web servers after we upgraded its memory.&#160;</p><p><img
style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Web server memory usage" border="0" alt="Web server memory usage" src="http://blog.straylightrun.net/wp-content/uploads/2009/12/zsweb001memorymonth.png" width="495" height="408" /></p><p>It makes sense that most of the memory not used by apps would be used by the OS to improve disk access.&#160; So seeing the memory graphs filled with orange is generally a good thing.&#160; After a few days, I watched the orange area grow and thought, “Great!&#160; LInux is putting all that extra memory to use.”&#160; I thought in my head that maybe it was caching images and CSS files to serve to Apache.&#160; But was that true?</p><p><strong><u>Looking At A Different Server</u></strong></p><p>Here is a memory graph from one of our database servers after the RAM upgrade.</p><p><img
style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Database server memory usage" border="0" alt="Database server memory usage" src="http://blog.straylightrun.net/wp-content/uploads/2009/12/zsdb001memorymonth.png" width="495" height="408" /></p><p>Again, I first thought that the OS was caching all that juicy database data from disk.&#160; The problem is that we don’t have 12GB of data, and that step pattern growth was suspiciously consistent.</p><p>Looking again at the web server graph, I saw giant downward spikes of blue color, where the buffer cache was emptied.&#160; (The blue is unused memory.)&#160; These occurred every day at 4 am, and on Sundays there’s a huge one.&#160; What happens every day at 4 am?&#160; The logs are rotated.&#160; And on Sundays, the granddaddy log of them all – the Apache log – is rotated.</p><p><strong><u>The Problem</u></strong></p><p>It was starting to make sense.&#160; Log files seem to take up most of the OS buffer cache on the web servers.&#160; Not optimal, I’m sure.&#160; And when they’re rotated, the data in the cache is invalidated and thus freed.</p><p>Here is a memory graph for one of our other database servers.</p><p> <img
style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Database server memory usage" border="0" alt="Database server memory usage" src="http://blog.straylightrun.net/wp-content/uploads/2009/12/zsdb002memorymonth.png" width="495" height="408" /></p><p>That step pattern growth is missing!&#160; In fact, most of RAM is unused.&#160; What is the difference between the first database server and this one?&#160; The first has the <code>`mysqldump`</code> backup.&#160; It occurs every night at 2:30 am, right when those step changes occur on its memory usage graph.</p><p>It was clear to me that most of the OS buffer cache was wasted on logs and backups and such.&#160; There had to be a way to tell the OS not to cache a file.&#160;</p><p><strong><u>The Solution</u></strong></p><p>Google gave me this page: <a
href="http://insights.oetiker.ch/linux/fadvise.html">Improving Linux performance by preserving Buffer Cache State</a>.&#160; I copied the little C program into a file and ran it on all the <code>`mysqldump`</code> backups.&#160; Here is the what happened to the memory usage.</p><p><img
style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Database server memory usage" border="0" alt="Database server memory usage" src="http://blog.straylightrun.net/wp-content/uploads/2009/12/zsdb001memoryweek.png" width="495" height="408" /></p><p>Quite a bit of buffer cache was freed.&#160; On that night’s backup, I logged the buffer cache size before the backup and after.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% cat 2008.08.21.02.30.log
Starting at Thu Aug 21 02:30:03 EDT 2008
=========================================
Cached:        4490232 kB
Cached:        5350908 kB
=========================================
Ending at Thu Aug 21 02:30:55 EDT 2008</pre></div></div><p>Just under a gigabyte increase in buffer cache size.&#160; What was the size of the new backup file?</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% ll 2008.08.21.02.30.sql
-rw-r--r-- 1 root root 879727872 Aug 21 02:30 2008.08.21.02.30.sql</pre></div></div><p>About 900MB.</p><p><strong><u>Did It Work?</u></strong></p><p>I used the C program on that page to ensure no database backups were cached by the OS.&#160; I did the same on the web servers in the <code>logrotate</code> config files.&#160; A couple days later, I checked the memory graph on the database server that performed the backup.&#160; Notice how the buffer cache did not fill up.&#160; It looked like the program worked, and the OS was free to cache more important things.</p><p><img
style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Database server memory usage" border="0" alt="Database server memory usage" src="http://blog.straylightrun.net/wp-content/uploads/2009/12/zsdb001memoryweek2.png" width="495" height="408" /></p> ]]></content:encoded> <wfw:commentRss>http://blog.straylightrun.net/2009/12/03/clearing-the-linux-buffer-cache/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Storing Apache Virtual Hosts In A Database</title><link>http://blog.straylightrun.net/2009/07/31/storing-apache-virtual-hosts-in-a-database/</link> <comments>http://blog.straylightrun.net/2009/07/31/storing-apache-virtual-hosts-in-a-database/#comments</comments> <pubDate>Fri, 31 Jul 2009 20:29:04 +0000</pubDate> <dc:creator>gerard</dc:creator> <category><![CDATA[Sysadmin]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[apr]]></category> <category><![CDATA[dbd]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[redhat enterprise]]></category> <category><![CDATA[rhel]]></category> <category><![CDATA[virtual host]]></category> <guid
isPermaLink="false">http://blog.straylightrun.net/?p=219</guid> <description><![CDATA[At work, we had set up some wildcard virtual hosts in Apache config, and that got us by for quite some time.  But the time came when we needed finer-grained control of where to send incoming requests for different domains.  I needed to store my virtual hosts in a Mysql database, mapping domains to project [...]]]></description> <content:encoded><![CDATA[<p>At work, we had set up some wildcard virtual hosts in Apache config, and that got us by for quite some time.  But the time came when we needed finer-grained control of where to send incoming requests for different domains.  I needed to store my virtual hosts in a Mysql database, mapping domains to project directories.</p><p>I&#8217;ll spare you the problems I ran into and overcame, and just list the steps to get this done.  These instructions are based on a 64-bit, RHEL 5 server running the pre-packaged Apache server.  So if you follow these instructions on a different setup, of course, filenames, directories, versions, etc. may differ.</p><p><strong><span
style="text-decoration: underline;">Install mod_vhost_dbd</span></strong></p><p>Download <a
href="http://code.google.com/p/dbd-modules/"><code>dbd-modules</code></a> from Google Code.  This is a great piece of code in the form of an Apache module that uses <a
href="http://httpd.apache.org/docs/2.2/mod/mod_dbd.html"><code>mod_dbd</code></a> and a DBD Mysql (or other database) driver to fetch the <code>DocumentRoot </code>for a given domain from a database.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% wget http://dbd-modules.googlecode.com/files/dbd-modules-1.0.5.zip</pre></div></div><p>Unzip the archive in a directory. As indicated on the website, <a
href="http://code.google.com/p/dbd-modules/wiki/Building">build and install the module</a>.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% apxs -c mod_vhost_dbd.c
% apxs -i mod_vhost_dbd.la</pre></div></div><p>This places <code>mod_vhost_dbd.so </code>in <code>/usr/lib64/httpd/modules</code>.  Enable both this module and <code>mod_dbd </code>by adding two lines to <code>httpd.conf</code>, or equivalently creating a new include file in<code> /etc/httpd/conf.d</code> containing these lines.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">LoadModule dbd_module modules/mod_dbd.so
LoadModule vhost_dbd_module modules/mod_vhost_dbd.so</pre></div></div><p>In true unit fashion, now might be a good time to restart Apache, just so you can be sure everything is working up to this point.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% service httpd restart</pre></div></div><p><strong><span
style="text-decoration: underline;">Install Mysql DBD Driver to APR</span></strong></p><p>Unfortunately, on my system, the Mysql DBD driver was nowhere to be found.  I had to rebuild Apache Portable Runtime (APR) utils with the Mysql driver enabled.</p><p>Download <a
href="http://apr.apache.org/"><code>apr</code></a> and <a
href="http://apr.apache.org/"><code>apr-util</code></a> from Apache.  Note these are not the latest versions, but the versions that <span
style="text-decoration: line-through;">matched the packages in</span> worked for RHEL 5.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% wget http://archive.apache.org/dist/apr-1.2.8.tar.bz2
% wget http://archive.apache.org/dist/apr-util-1.2.8.tar.bz2</pre></div></div><p>Unpack and untar these archives in the same parent directory.</p><p>Build and install APR.  Now, I do not think this is absolutely necessary, but it seems like a good idea to keep the versions in sync.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% ./configure --prefix=/usr
% make
% make install</pre></div></div><p>Build and install <code>apr-util</code>.  Due to licensing issues, <code>apr-util </code>does not actually contain the Mysql DBD driver until <code>apr-util-1.2.12</code>.  Prior to that version, it must be downloaded separately, and the configure script rebuilt.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% wget http://apache.webthing.com/svn/apache/apr/apr_dbd_mysql.c
% ./buildconf --with-apr=../apr-1.2.7</pre></div></div><p>Now for the three commands every Linux admin loves.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% ./configure --prefix=/usr --with-apr=/usr --libdir=/usr/lib64 --with-expat=builtin --with-ldap-include=/usr/include --with-ldap-lib=/usr/lib64 --with-ldap=ldap --with-mysql
% make
% make install</pre></div></div><p>The first time I tried this, Apache could not find any LDAP-related modules.  Adding those configure switches seemed to do the trick.  Restart Apache.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">% service httpd restart</pre></div></div><p>Apache should now be able to query a Mysql database to get the <code>DocumentRoot </code>for a domain.  My <code>VirtualHost</code> block looked something like this.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">&lt;VirtualHost *:80&gt;
    ServerName *.example.com
    DocumentRoot &quot;/path/to/default/document/root&quot;
&nbsp;
    DBDriver mysql
    DBDParams host=localhost,user=root,pass=secret,dbname=vhosts
&nbsp;
    DBDocRoot &quot;SELECT path FROM vhosts WHERE host = %s&quot;  HOSTNAME
&lt;/VirtualHost&gt;</pre></div></div><p>For more details and instructions on <a
href="http://code.google.com/p/dbd-modules/wiki/mod_vhost_dbd"><code>mod_vhost_dbd</code> configuration directives, read the project wiki</a>.</p> ]]></content:encoded> <wfw:commentRss>http://blog.straylightrun.net/2009/07/31/storing-apache-virtual-hosts-in-a-database/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Tip Of The Day: Removing .htaccess</title><link>http://blog.straylightrun.net/2009/06/17/tip-of-the-day-removing-htaccess/</link> <comments>http://blog.straylightrun.net/2009/06/17/tip-of-the-day-removing-htaccess/#comments</comments> <pubDate>Wed, 17 Jun 2009 20:48:21 +0000</pubDate> <dc:creator>gerard</dc:creator> <category><![CDATA[Performance]]></category> <category><![CDATA[Sysadmin]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[htaccess]]></category> <category><![CDATA[tips]]></category> <guid
isPermaLink="false">http://blog.straylightrun.net/?p=205</guid> <description><![CDATA[At work, every project has an .htaccess file containing at the least some mod_rewrite rules.  This way, all I need to do to run a project is check it out of version control.  I don&#8217;t need to modify my local Apache configuration. But turning this option on and allowing .htaccess files may be a performance [...]]]></description> <content:encoded><![CDATA[<p>At work, every project has an <code>.htaccess</code> file containing at the least some <code>mod_rewrite </code>rules.  This way, all I need to do to run a project is check it out of version control.  I don&#8217;t need to modify my local Apache configuration.</p><p>But turning this option on and allowing <code>.htaccess</code> files may be a performance hit.  More specifically, enabling the <code><a
href="http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride">AllowOverride</a> </code>option in Apache is a performance hit.  The <a
href="http://httpd.apache.org/docs/2.2/misc/perf-tuning.html">Apache docs</a> sums up the problem best:</p><blockquote><p> &#8220;Wherever in your URL-space you allow overrides (typically <code>.htaccess</code> files) Apache will attempt to open <code>.htaccess</code> for each filename component. For example,</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="xml" style="font-family:monospace;">DocumentRoot /www/htdocs
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Directory</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   AllowOverride all
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div><p>and a request is made for the URI <code>/index.html</code>. Then Apache will attempt to open <code>/.htaccess</code>, <code>/www/.htaccess</code>, and <code>/www/htdocs/.htaccess</code>.&#8221;</p></blockquote><p>So I disabled all <code>.htaccess </code>files in production, and inserted each file&#8217;s individual <code>mod_rewrite </code>rules into the main Apache config file. After a quick <a
href="http://blog.straylightrun.net/2009/04/23/apache-bench/">Apache Bench</a> run, one project looked around 3% faster. Note that there are a few other useful optimizations on that page.</p> ]]></content:encoded> <wfw:commentRss>http://blog.straylightrun.net/2009/06/17/tip-of-the-day-removing-htaccess/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>ETags</title><link>http://blog.straylightrun.net/2009/01/30/etags/</link> <comments>http://blog.straylightrun.net/2009/01/30/etags/#comments</comments> <pubDate>Fri, 30 Jan 2009 21:04:11 +0000</pubDate> <dc:creator>gerard</dc:creator> <category><![CDATA[Performance]]></category> <category><![CDATA[Sysadmin]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[etags]]></category> <guid
isPermaLink="false">http://blog.straylightrun.net/2009/01/30/etags/</guid> <description><![CDATA[This one is filed under &#8220;that&#8217;s pretty picky, but I guess it couldn&#8217;t hurt.&#8221; The Entity Tags (ETags) HTTP header is a string that uniquely identifies a specific version of resource. When the browser first downloads a resource, it stores the ETag. When it requests it again, it sends along the ETag to the server. [...]]]></description> <content:encoded><![CDATA[<p>This one is filed under &#8220;that&#8217;s pretty picky, but I guess it couldn&#8217;t hurt.&#8221;</p><p>The Entity Tags (ETags) HTTP header is a string that uniquely identifies a specific version of resource. When the browser first downloads a resource, it stores the ETag. When it requests it again, it sends along the ETag to the server. If the server sees the same ETag, it will respond with a 304 Not Modified response, saving the download.</p><p>The problem is that the default format for the ETag (in Apache) is <em>inode-size-timestamp</em>. And the <em>inode </em>will be different from server to server, meaning the server may see a different ETag from the browser, even thought it is in fact an identical file.</p><p><a
href="http://developer.yahoo.com/performance/rules.html#etags">According to Yahoo</a>:</p><blockquote><p>The end result is ETags generated by Apache and IIS for the exact same component won&#8217;t match from one server to another. If the ETags don&#8217;t match, the user doesn&#8217;t receive the small, fast 304 response that ETags were designed for; instead, they&#8217;ll get a normal 200 response along with all the data for the component. If you host your web site on just one server, this isn&#8217;t a problem. But if you have multiple servers hosting your web site, and you&#8217;re using Apache or IIS with the default ETag configuration, your users are getting slower pages, your servers have a higher load, you&#8217;re consuming greater bandwidth, and proxies aren&#8217;t caching your content efficiently.</p></blockquote><p>There is another scenario where it isn&#8217;t a problem: if you are using sticky sessions in your load balancer.</p><p>In any case, as stated above, it couldn&#8217;t hurt to rectify this. So I configured the ETag format in Apache to exclude the inode, and use only size and timestamp.</p><div
class="wp_syntax"><div
class="code"><pre class="sh" style="font-family:monospace;">FileETag MTime Size</pre></div></div><p>So files across servers have the same ETag.</p> ]]></content:encoded> <wfw:commentRss>http://blog.straylightrun.net/2009/01/30/etags/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
