<?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>dotvoid.com &#187; apache</title>
	<atom:link href="http://www.dotvoid.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotvoid.com</link>
	<description>Experiments and thoughts in PHP and javascript</description>
	<lastBuildDate>Tue, 25 May 2010 21:53:20 +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>Setting up a development environment with apache-2.2.6</title>
		<link>http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/</link>
		<comments>http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 22:16:39 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=243</guid>
		<description><![CDATA[I recently bought a new laptop as my new development box. A nice 17&#8243; screen with 1920*1200. So now I was to setup a PHP development environment for all the projects I&#8217;m working on. I downloaded Apache 2.2.6, PHP 5.2.4 and MySQL 5.0.45. I compiled and installed them and finally added a few virtual hosts. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently bought a new laptop as my new development box. A nice 17&#8243; screen with 1920*1200. So now I was to setup a PHP development environment for all the projects I&#8217;m working on. I downloaded Apache 2.2.6, PHP 5.2.4 and MySQL 5.0.45. I compiled and installed them and finally added a few virtual hosts. None of the vhosts worked. They all gave me</p>
<pre>"client denied by server configuration: ..."</pre>
<p>I had missed that apache now ships with a slightly different configuration for the / directory to</p>
<pre>&lt;Directory /&gt;
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
&lt;/Directory&gt;</pre>
<p>The <span style="font-style: italic;">Order deny,allow</span> and <span style="font-style: italic;">Deny from all</span> makes the virtual hosts inaccessible by default. When I googled it I saw many forum and blog posts asking about this issue.</p>
<p>To fix it you can either remove/change the lines. But that is probably not a good idea. Better is to explicitly specify which directories that apache are allowed to serve. So for me and my project setup it was as simple as adding a new directory directive opening up my www directories for all the projects.</p>
<pre>&lt;Directory /&gt;
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
&lt;/Directory&gt;

&lt;Directory "/home/myusername/Projects/*/www"&gt;
    Order deny,allow
    Allow from all
&lt;/Directory&gt;</pre>
<p>I hope this short explanation helps a few people looking for a solution to the problem.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/&amp;title=Setting+up+a+development+environment+with+apache-2.2.6" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/&amp;t=Setting+up+a+development+environment+with+apache-2.2.6" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/&amp;title=Setting+up+a+development+environment+with+apache-2.2.6&amp;summary=I%20recently%20bought%20a%20new%20laptop%20as%20my%20new%20development%20box.%20A%20nice%2017%22%20screen%20with%201920%2A1200.%20So%20now%20I%20was%20to%20setup%20a%20PHP%20development%20environment%20for%20all%20the%20projects%20I%27m%20working%20on.%20I%20downloaded%20Apache%202.2.6%2C%20PHP%205.2.4%20and%20MySQL%205.0.45.%20I%20compiled%20and%20installed%20them%20and%20finally%20added%20a%20few%20virtual%20ho&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/&amp;title=Setting+up+a+development+environment+with+apache-2.2.6" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Setting+up+a+development+environment+with+apache-2.2.6+-+http://b2l.me/wu9cs&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2007/11/setting-up-a-development-environment-with-apache-226/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing the user agent string using PHP</title>
		<link>http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/</link>
		<comments>http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/#comments</comments>
		<pubDate>Tue, 02 Jan 2007 13:26:08 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=206</guid>
		<description><![CDATA[
Recently I experimented a bit with an Apache log file analyzer written in PHP. It&#8217;s not all that difficult were it not for trying to parse the browser, or user agent, string. There are in fact two RFC documents, RFC 1945 and RFC 2068, that define how a user agent string should be written. Still [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>Recently I experimented a bit with an Apache log file analyzer written in PHP. It&#8217;s not all that difficult were it not for trying to parse the browser, or user agent, string. There are in fact two RFC documents, <a href="http://www.faqs.org/rfcs/rfc1945.html">RFC 1945</a> and <a href="http://www.faqs.org/rfcs/rfc2068.html">RFC 2068</a>, that define how a user agent string should be written. Still many does not adhere to these standards and many write the interesting details in the comment field only. There is a good article at texSoft.it on how to <a href="http://www.texsoft.it/index.php?c=software&amp;m=sw.php.useragent&amp;l=it">identify the user agent</a> and I have tried to steal bits and pieces of my time  to implement the algorithm.</p>
<p>For my purposes I don&#8217;t care much for the operating system details. This is the result so far. I&#8217;m still not very satisfied but I thought maybe other people might be interested and maybe help out. Maybe there is something better out there? I&#8217;d be happy for any input.</p>
<pre>function parseUserAgent($ua)
  {

    $userAgent = array();
    $agent = $ua;
    $products = array();

    $pattern  = "([^/[:space:]]*)" . "(/([^[:space:]]*))?"
      ."([[:space:]]*\[[a-zA-Z][a-zA-Z]\])?" . "[[:space:]]*"
      ."(\\((([^()]|(\\([^()]*\\)))*)\\))?" . "[[:space:]]*";

    while( strlen($agent) &gt; 0 )
      {
        if ($l = ereg($pattern, $agent, $a))
          {
            // product, version, comment
            array_push($products, array($a[1],    // Product
                                        $a[3],    // Version
                                        $a[6]));  // Comment
            $agent = substr($agent, $l);
          }
        else
          {
            $agent = "";
          }
      }

    // Directly catch these
    foreach($products as $product)
      {
        switch($product[0])
          {
          case 'Firefox':
          case 'Netscape':
          case 'Safari':
          case 'Camino':
          case 'Mosaic':
          case 'Galeon':
          case 'Opera':
            $userAgent[0] = $product[0];
            $userAgent[1] = $product[1];
            break;
          }
      }

    if (count($userAgent) == 0)
      {
        // Mozilla compatible (MSIE, konqueror, etc)
        if ($products[0][0] == 'Mozilla' &amp;&amp;
            !strncmp($products[0][2], 'compatible;', 11))
          {
            $userAgent = array();
            if ($cl = ereg("compatible; ([^ ]*)[ /]([^;]*).*",
                           $products[0][2], $ca))
              {
                $userAgent[0] = $ca[1];
                $userAgent[1] = $ca[2];
              }
            else
              {
                $userAgent[0] = $products[0][0];
                $userAgent[1] = $products[0][1];
              }
          }
        else
        {
          $userAgent = array();
          $userAgent[0] = $products[0][0];
          $userAgent[1] = $products[0][1];
        }
      }

    return $userAgent;
  }</pre>
</div>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/&amp;title=Parsing+the+user+agent+string+using+PHP" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/&amp;t=Parsing+the+user+agent+string+using+PHP" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/&amp;title=Parsing+the+user+agent+string+using+PHP&amp;summary=%0D%0A%0D%0ARecently%20I%20experimented%20a%20bit%20with%20an%20Apache%20log%20file%20analyzer%20written%20in%20PHP.%20It%27s%20not%20all%20that%20difficult%20were%20it%20not%20for%20trying%20to%20parse%20the%20browser%2C%20or%20user%20agent%2C%20string.%20There%20are%20in%20fact%20two%20RFC%20documents%2C%20RFC%201945%20and%20RFC%202068%2C%20that%20define%20how%20a%20user%20agent%20string%20should%20be%20written.%20Still%20&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/&amp;title=Parsing+the+user+agent+string+using+PHP" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Parsing+the+user+agent+string+using+PHP+-+http://b2l.me/wtw44&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2007/01/parsing-the-user-agent-string-using-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Google Web Accelerator</title>
		<link>http://www.dotvoid.com/2005/05/google-web-accelerator/</link>
		<comments>http://www.dotvoid.com/2005/05/google-web-accelerator/#comments</comments>
		<pubDate>Thu, 12 May 2005 10:08:28 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=129</guid>
		<description><![CDATA[
Recently the Google Web Accelerator (GWA)has received a lot of attention from web application developers. Rightly so. When installing GWA for use in your browser it speeds up surfing by prefetching pages. This can be very useful but also extremely dangerous as it has very bad side effects on many (badly designed) web applications. Why? [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>Recently the <a href="http://webaccelerator.google.com/">Google Web Accelerator</a> (GWA)has received a lot of attention from web application developers. Rightly so. When installing GWA for use in your browser it speeds up surfing by prefetching pages. This can be very useful but also extremely dangerous as it has very bad side effects on many (badly designed) web applications. Why? When you open up a web page GWA scans through the page looking for all the links and prefetch all the pages pointed to by the links. This is where things can go really wrong&#8230;</div>
<div class="itemview">
<p>The reason is that many web developers don&#8217;t have a clue about the difference between the http methods GET and POST. Some know approximately the technical difference but not why one should use one method over the other. According to <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">the RFC</a> the GET method should never &#8220;alter the world&#8221;. In other words &#8211; POST should be used whenever there is a need to alter data and GET should only ever be used to fetch data.</p>
<p>So what does this have to do the Google Web Accelerator? It is very common in web applications to present, for example, lists of data like users or articles with links to either display or delete the data.</p>
<p>Consider what happens if the application user has GWA installed when all the links are prefetched. All the links will be invisibly followed and all data deleted. Many applications protect links like this with onclick handlers that ask the user if they want to delete the data. As the GWA has no concept of javascript it just ignores this fact and the links will be prefetched anyway with potentially disastrous results.</p>
<p>It is not Google that has done anything wrong. They follow the guidelines in the RFC on the correct usage of GET and POST.</p>
<p>Personally I think my applications are safe. I usually follow the guidelines on GET and POST but not always. But as I use only javascript calls to fetch or do things in my applications I am safe.</p>
<p>Safe</p>
<pre>&lt;a href="#" onclick="deleteUser(372);"&gt;Delete user&lt;/a&gt;</pre>
<p>Very dangerous (and wrong)</p>
<pre>&lt;a href="deleteUser.php?id=372"&gt;Delete user&lt;/a&gt;</pre>
<p>A safeguard for Apache</p>
<pre>RewriteCond %{HTTP:x-moz} ^prefetch
RewriteRule ^/*admin/.* - [F,L]</pre>
<p>I found the Apache solution on the blog of <a href="http://blog.bitflux.ch/archive/2005/05/12/prevent-prefetching-from-google-s-web-accelerator.html">Christian Stocker</a> who got it from the <a href="http://syntaxblog.forumone.com/archives/66-Google-Web-Accelerator-Fix-in-CVS.html">Syntax CMS blog</a> through <a href="http://planet.oscom.org/">Planet OSCOM</a>. (The blogging world of today&#8230;) Anyway, it is most likely a good idea to review your applications before users of your applications starts using GWA and this becomes a serious issue.</div>
<p><a name="comments"></a></p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2005/05/google-web-accelerator/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2005/05/google-web-accelerator/&amp;title=Google+Web+Accelerator" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2005/05/google-web-accelerator/&amp;t=Google+Web+Accelerator" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2005/05/google-web-accelerator/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2005/05/google-web-accelerator/&amp;title=Google+Web+Accelerator&amp;summary=%0D%0A%0D%0ARecently%20the%20Google%20Web%20Accelerator%20%28GWA%29has%20received%20a%20lot%20of%20attention%20from%20web%20application%20developers.%20Rightly%20so.%20When%20installing%20GWA%20for%20use%20in%20your%20browser%20it%20speeds%20up%20surfing%20by%20prefetching%20pages.%20This%20can%20be%20very%20useful%20but%20also%20extremely%20dangerous%20as%20it%20has%20very%20bad%20side%20effects%20on%20man&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2005/05/google-web-accelerator/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2005/05/google-web-accelerator/&amp;title=Google+Web+Accelerator" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Google+Web+Accelerator+-+http://b2l.me/wyupx&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2005/05/google-web-accelerator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Awstats with virtual hosts on Apache</title>
		<link>http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/</link>
		<comments>http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/#comments</comments>
		<pubDate>Tue, 04 Jan 2005 10:48:24 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=42</guid>
		<description><![CDATA[
Awstats is a very good weblog analyzer. It produce loads of statistics about your visitors and their behaviour. The first time it can be a bit tricky to setup if you have many virtual hosts. However good the application is, the documentation is a classical example of when programmers write the manual. They understand everything [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p><a href="http://www.awstats.org/">Awstats</a> is a very good weblog analyzer. It produce loads of statistics about your visitors and their behaviour. The first time it can be a bit tricky to setup if you have many virtual hosts. However good the application is, the documentation is a classical example of when programmers write the manual. They understand everything so it all makes perfect sense to them. This article describes how to setup the awstats package with authentication for multiple virtual hosts and how to use logrotate and scripts to automate tasks.</div>
<div class="itemview">
<h3>Installing awstats</h3>
<p>For this I used Fedora Core 2 with Apache 1.3 installed in /opt/apache-1.3/. I install awstats from an RPM downloaded from <a href="http://www.rpmfind.net/">rpmfind.net</a>. At the time of my writing this the latest rpm available is awstats-6.2-1.1.fc2.rf.noarch.rpm. The default installation directory is /var/www/awstats and the config files are placed in /etc/awstats. The installation directory is not the optimal as didn&#8217;t install apache in that location but it doesn&#8217;t really matter. After installation these lines should be present at the bottom of your httpd.conf files. If commented out, uncomment them.</p>
<pre>Alias /awstatsclasses "/var/www/awstats/classes/"
Alias /awstatscss "/var/www/awstats/css/"
Alias /awstatsicons "/var/www/awstats/icon/"
ScriptAlias /awstats "/var/www/awstats/"

&lt;Directory "/var/www/awstats"&gt;
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
&lt;/Directory&gt;</pre>
<p>The way I set it up requires basic authentication. Adding the required lines to the Directory part leaves it like below. In this case I specified the password file to reside in the same place as the rest of the awstats configuration. The awstats.pwd file will be created later.</p>
<pre>&lt;Directory "/var/www/awstats"&gt;
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthType Basic
    AuthName stats
    AuthUserFile /etc/awstats/awstats.pwd
    require valid-user
&lt;/Directory&gt;</pre>
<h3>Setup apache logging</h3>
<p>Awstats recommend you to split your logs between your virtual hosts so that each virtual host has its own apache access_log file. Even so I like to keep logging for all the virtual hosts in the same log file. I think it is a bit easier to handle the logfile and it also simplifies logrotating.</p>
<p>As I&#8217;m keeping all virtual hosts in the same logfile I need to make sure the virtual host is written to each line. This does not come out of the box and a small change in httpd.conf is needed. In httpd.conf you will find a few lines that specify different log formats. Per default the combined log format should be used. This is also what awstats recommend. It is defined in httpd.conf.</p>
<pre>LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined</pre>
<p>As I want to be able to differantiate log entries between different virtual hosts I want the combined format plus the virtual host. So I create my own log format that I call cplus. This format has %v prepended to it which will put the virtual host first on each log entry. I add the following line to httpd.conf</p>
<pre>LogFormat "%v %h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" cplus</pre>
<p>I also need to tell apache to use the cplus log format instead of the combined format by changing the CustomLog directive to look like below.</p>
<pre>CustomLog /opt/apache-1.3/logs/access_log cplus</pre>
<p>I restart apache and have a look in access_log to verify that the virtual host is written on each log entry.</p>
<h3>Configure awstats</h3>
<p>With apache done it is time to configure awstats. I&#8217;m only interested in the file awstats.model.conf in /etc/awstats. So the first thing I do is to remove the everything else from /etc/awstats that was created during installation. This file, awstats.model.conf, is going to be the template for all other awstats.*.conf files as awstats needs one config file per virtual host. Setting up a new virtual host manually is boring as well as error prone so I create scripts to do most of the job. This is also the case with awstats.</p>
<p>There are several configuration changes needed in awstats.model.conf. As I don&#8217;t use the combined log format I have to specify a custom log format. In several places I change the values to something that is easier to parse with a script. Applicable entries and their values are:</p>
<pre>LogFile="/opt/apache-1.3/logs/access_log"
LogFormat = "%virtualname %host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
SiteDomain="$DOMAIN"
HostAliases="$ALIASES"
DirData="/home/$USERNAME/awstats"
AllowAccessFromWebToAuthenticatedUsersOnly=1
AllowAccessFromWebToFollowingAuthenticatedUsers="$USERNAME"</pre>
<p>There are loads of other stuff you can tweak but these are the ones important for this setup.</p>
<h3>Set up statistics for a host</h3>
<pre>&lt;VirtualHost *:80&gt;
    ServerName www.mysite300.org
    ServerAlias mysite300.org
    DocumentRoot /home/mysite300_org/www
    ServerAdmin info@mysite300.org
&lt;/VirtualHost&gt;</pre>
<p>Everything is now in place to setup awstats for an individual virtual host. The above is a minimal example of a virtual host section in httpd.conf. If I want to manually setup awstats for www.mysite300.org I have to create a directory to host the statistics files. I have to copy awstats.model.conf to awstats.www.mysite300.org and change all the configuration values by hand. Then I need to run htpasswd to add a username and password to /etc/awstats/awstats.pwd to allow someone to see the statistics.</p>
<p>As I am lazy I want to cut this three minute job to a few seconds. I have created the following small script, addstat.sh, to ask the right questions and then perform the task. This script is run as root. It could be prettier but it gets the job done.</p>
<pre>#!/bin/bash
echo "Enter the username:"
read WUSERNAME

ACCESS_FILE="/etc/awstats/awstats.pwd"
STAT_DIR="/home/$WUSERNAME/awstats"

echo "Enter the password:"
read PASSWORD

echo "Enter the main domain:"
read DOMAIN

echo "Enter aliases separated by space:"
read ALIASES

# Create the statistics directory
if [ -d $STAT_DIR ]; then
    echo "Statistics dir already exist"
else
    mkdir $STAT_DIR
fi

# Create the virtual host awstats.conf
cat /etc/awstats/awstats.model.conf | \
sed -e "s/\\\$DOMAIN/$DOMAIN/g" | \
sed -e "s/\\\$USERNAME/$WUSERNAME/g" | \
sed -e "s/\\\$ALIASES/$ALIASES/g" &gt; \
"/etc/awstats/awstats.$DOMAIN.conf"

# Add user/password to password file
if [ -e $ACCESS_FILE ]; then
    /opt/apache-1.3/bin/htpasswd -bm $ACCESS_FILE $WUSERNAME $PASSWORD
else
    /opt/apache-1.3/bin/htpasswd -bm -c $ACCESS_FILE $WUSERNAME $PASSWORD
fi</pre>
<p>After running this script to setup awstats for the example virtual host the user mysite300_org can go to http://www.mysite300.org/awstats/awstats.pl to view his statistics. The user will be presented with a login form and only allowed through if he presents the correct credentials.</p>
<h3>Generating statistics</h3>
<p>Now that I have run the script and setup statistics for this virtual host I want to generate statistics as well. Because it is still empty. I can do this manually through</p>
<pre>/var/www/awstats/awstats.pl -update -config=www.mysite300.org</pre>
<p>I have many virtual hosts and I want the statistics to be updated every day. So this is not an option. Creating a script and run it from a cron job could be a good idea. But an even better idea is to use logrotate to rotate the apache logs and have logrotate run our script.</p>
<p>A simple script, genstat.sh, to generate statistics for all awstats.*.conf files in /etc/awstats except awstats.model.conf is needed. I put the script in /root/scripts.</p>
<pre>#!/bin/bash
CONF_DIR="/etc/awstats"
CONF_EXT="conf"

if [ ! -d "$CONF_DIR" ]; then
  echo "$CONF_DIR does not exist"
  exit 1
else
  cd $CONF_DIR
fi

for cfg in *.$CONF_EXT; do
if [ "$cfg" != "awstats.model.conf" ]; then
   site=`echo $cfg|sed -e "s/awstats.//g" | sed -e "s/.conf//g"`
   /var/www/awstats/awstats.pl -update -config="$site"
fi
done</pre>
<p>Then I need to configure logrotate.conf in /etc to run this script prior to rotating the logs. If rpm was used to install apache it could have its own file in /etc/logrotate.d/. I normally install apache manually, so I add this entry directly in logrotate.conf.</p>
<pre>/opt/apache-1.3/logs/access_log {
   rotate 31
   daily
   compress
   sharedscripts
   prerotate
     /root/scripts/dailystat.sh
   endscript
   postrotate
     /opt/apache-1.3/bin/apachectl restart
   endscript
}</pre>
<p>There is one problem one can encounter with logrotate. There are many vulnerable applications on the web. When hosting applications I don&#8217;t have any control over I (ofcourse) try to secure the system as good as possible. As a security measure I have /tmp mounted with the options nosuid and noexec. The specific line in /etc/fstab looks like below.</p>
<pre>LABEL=/tmp /tmp ext3 defaults,nosuid,noexec 1 2</pre>
<p>Crackers and worms often exploit vulnerable web applications to upload scripts and run them from /tmp. Mounting /tmp with the noexec option is a good way to make sure this cannot happen even if there are vulnerable applications on the system. If you haven&#8217;t done so already &#8211; now is a good time to fix this. However, this also stops logrotate as it runs scripts from /tmp (or whatever you have TMPDIR defined as).</p>
<p>Logrotate is run daily per default. The acutal script can be found in /etc/cron.daily/logrotate. To fix this I create a tmp directory, /tmp_safe, that is going to be used by logrotate only. Then I add the following to the top of /etc/cron.daily/logrotate.</p>
<pre>export TMPDIR=/tmp_safe</pre>
<p>No logrotate will use /tmp_safe as a tmp directory instead of /tmp. All other applications running on the system will still use /tmp as normal.</p>
<h3>Wrapping it up</h3>
<p>Now I have a working awstats installation and logrotate rotates my apache access_log. The logs are compressed and saved for 31 days. When I want to add statistics possibilites for a virtual host I just run the script addstat.sh. Life is simple again.</p>
<p><strong>Files created</strong></p>
<ul>
<li>/root/scripts/addstat.sh</li>
<li>/root/scripts/genstat.sh</li>
</ul>
<p><strong>Files changed</strong></p>
<ul>
<li>/opt/apache-1.3/conf/httpd.conf</li>
<li>/etc/awstats/awstats.model.conf</li>
<li>/etc/logrotate.conf</li>
<li>/etc/cron.daily/logrotate</li>
<li>/etc/fstab</li>
</ul>
</div>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/&amp;title=Awstats+with+virtual+hosts+on+Apache" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/&amp;t=Awstats+with+virtual+hosts+on+Apache" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/&amp;title=Awstats+with+virtual+hosts+on+Apache&amp;summary=%0D%0A%0D%0AAwstats%20is%20a%20very%20good%20weblog%20analyzer.%20It%20produce%20loads%20of%20statistics%20about%20your%20visitors%20and%20their%20behaviour.%20The%20first%20time%20it%20can%20be%20a%20bit%20tricky%20to%20setup%20if%20you%20have%20many%20virtual%20hosts.%20However%20good%20the%20application%20is%2C%20the%20documentation%20is%20a%20classical%20example%20of%20when%20programmers%20write%20the%20m&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/&amp;title=Awstats+with+virtual+hosts+on+Apache" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Awstats+with+virtual+hosts+on+Apache+-+http://b2l.me/wufs2&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2005/01/awstats-with-virtual-hosts-on-apache/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>MySQL 4, Apache 1.3 and PHP 4.3 on Solaris x86</title>
		<link>http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/</link>
		<comments>http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/#comments</comments>
		<pubDate>Thu, 02 Sep 2004 07:20:26 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=35</guid>
		<description><![CDATA[
Yesterday I decided it was time to get a proper PHP 4 environment configured on my new machine running the x86 version of Solaris 9. I know going outside Windows or Linux with PHP sometimes can be tricky. I haven&#8217;t used PHP on Solaris since my time at AOL in Dublin three years ago, so I decided to write down exactly [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>Yesterday I decided it was time to get a proper PHP 4 environment configured on my new machine running the x86 version of Solaris 9. I know going outside Windows or Linux with PHP sometimes can be tricky. I haven&#8217;t used PHP on Solaris since my time at AOL in Dublin three years ago, so I decided to write down exactly how, what and why I did things. I expected it to be a bit simpler then last time as I planned to use Apache rather than IPlanet (or whatever the name is today, it seems to change at least once a week). So my plan was to install a pretty standard LAMP environment. That is without the L ofcourse.</p></div>
<div class="itemview">
<h3>Preparations</h3>
<p>The first thing I had to do was to download the different GNU packages needed to compile MySQL, PHP and many other open source projects on Solaris. These packages can all be found on <a href="http://www.sunfreeware.com/">Sunfreeware.com</a>. The packages I installed, by default under /usr/local,  were:</p>
<ul>
<li>gcc</li>
<li>gmake</li>
<li>flex</li>
<li>bison</li>
<li>m4</li>
<li>autoconf</li>
<li>automake</li>
<li>gzip</li>
<li>tar</li>
<li>GNU sed</li>
<li>libiconv</li>
</ul>
<p>All packages are easy to install using <em>pkgadd</em>. Care needs to be taken to set the system paths correctly after the installation. I used the command <em>crle -u -l /usr/local/lib</em> to add the lib directory to the system defaults. Then I added <em>/usr/local/bin</em> first in my PATH to make sure GNU versions take precedence if there are any conflicts. For example the package m4 could be found on the system already. I also appended <em>/usr/ccs/bin</em> last to the PATH as there are programs there needed for compilation and linking.</p>
<h3>MySQL</h3>
<p>Having the environment setup as I wanted it I set my eyes on installing MySQL. I couldn&#8217;t find an official binary package for Solaris 9 x86 so I had to build it myself. I downloaded the source from <a href="http://www.mysql.com/">mysql.com</a>, quickly unpacked it and failed miserably at compiling it.</p>
<p>A quick research using Google gave me <a href="http://forum.sun.com/thread.jsp?forum=11&amp;thread=20228">the answer</a>. The command <span style="font-style: italic;">mkheaders</span> refused due to paths not being found. So additionally I had to create a softlink as the paths for some reason differed. After creating the symlink I could generate the gcc header files. The exact commands issued are as below.</p>
<pre># ln -s /usr/local/lib/gcc /usr/local/lib/gcc-lib
# cd /usr/local/libexec/gcc/i386-pc-solaris2.9/\
  3.4.1/install-tools
# ./mkheaders</pre>
<p>Then I tried compiling MySQL again. This time, everything could be done by the book. For sake of convenience &#8211; here&#8217;s a near copy from the MySQL manual.</p>
<pre># ./configure --prefix=/usr/local/mysql
# make &amp;&amp; make install
# cp support-files/my-medium.cnf /etc/my.cnf</pre>
<pre># cd /usr/local/mysql
# groupadd mysql
# useradd -g mysql mysql
# chown -R root .
# chown -R mysql var
# chgrp -R mysql .</pre>
<p>The only thing left then is to start the MySQL daemon and set the root password.</p>
<pre># bin/mysqld_safe --user=mysql
# bin/mysqladmin -u root password XXXXXX
# bin/mysqladmin -u root -h myhost password XXXXXX</pre>
<h3>Installing gd</h3>
<p>I need gd for, among other things, thumbnail generation. As I wanted to download and compile as little as possible a quick check revealed that freetype, libjpeg, libpng and libiconv already existed in my default Solaris 9 installation. The libraries can be found under the <em>/usr/sfw</em> directory.</p>
<p>I wanted the newest version of gd as GIF support is now added again after being removed for several years due to Unisys suddenly starting do demand licensing fees for their LZW patent a few years ago. So I could not use the slightly older gd available as a package at sunfreeware.</p>
<p>I downloaded version 2.0.28 and tried to compile it. However, I could not get it to compile using the libiconv already installed. Instead I had to download libiconv from sunfreeware and install it under <em>/usr/local</em>. The following configure command was what I ended up with to get gd to compile.</p>
<pre># ./configure \
  --prefix=/usr/local \
  --with-freetype=/usr/sfw \
  --with-png=/usr/sfw \
  --with-jpeg=/usr/sfw \
  --with-libiconv-prefix=/usr/local</pre>
<p>After that compiling the package was a breeze.</p>
<pre># make &amp;&amp; make install</pre>
<h3>On to apache</h3>
<p>Apache must be the easiest application around to build on different platforms. I have never experienced any problems building a stable apache release on any unix platform. I did once have problems getting it to run on NT 4 when the windows version still was marked unstable. I guess that could be expected though. So creating a standard build of apache is very straight forward.</p>
<pre># ./configure --prefix=/usr/local/apache-1.3.31 \
  --enable-module=so
# make &amp;&amp; make install</pre>
<h3>PHP &#8211; finally</h3>
<p>Compiling PHP became, as it turned out, a bit tricky becaused of my decision to enable gd support. The reason was that the PHP configure script didn&#8217;t list libiconv when checking that all the gd functions were correct. The configure script just said &#8220;no&#8221; to all the gd functions and refused to create the makefiles. After awhile I looked through the generated config.log. This revealed that what really failed was not actually gd. When loading gd to check what functions were available it failed to find symbols from libiconv. This must either be a bug in the configure script or more probable a problem with my Solaris 9 environment and the library paths.</p>
<p>So prior to running the configure script I had to manually amend the configure script and add <em>-liconv</em> in all places where <em>-lgd</em> could be found. That did the trick and the script happily trotted along as it should.</p>
<pre># ./configure \
  --with-apxs=/usr/local/apache-1.3.31/bin/apxs \
  --with-mysql=/usr/local/mysql/ \
  --with-gd=/usr/local \
  --with-freetype-dir=/usr/sfw \
  --enable-gd-native-ttf \
  --with-png-dir=/usr/sfw \
  --with-zlib-dir=/usr/sfw \
  --with-jpeg-dir=/usr/sfw</pre>
<pre># make &amp;&amp; make install</pre>
<p>After that I added the directives needed in httpd.conf to enable PHP4. Actually I only had to add the second line below as the LoadModule directive was already present.</p>
<pre>LoadModule php4_module libexec/libphp4.so
AddType application/x-httpd-php .php</pre>
<p>And finally, at 03:43 AM, I could verify the installation and configuration using the simple php script with a call to phpinfo(). Of course it worked like a charm.</p>
<p>All that remains now is to get Apache 2 and PHP 5 up and running alongside. I still haven&#8217;t figured out if the good PHP folks recommend Apache 2 for production yet. Anyways,<br />
that&#8217;ll be a project for another night.</p></div>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;title=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;t=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;title=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86&amp;summary=%0D%0A%0D%0AYesterday%20I%20decided%20it%20was%20time%20to%20get%20a%20proper%20PHP%204%C2%A0environment%20configured%20on%20my%20new%20machine%C2%A0running%C2%A0the%C2%A0x86%20version%20of%20Solaris%209.%C2%A0I%20know%20going%20outside%20Windows%20or%20Linux%20with%20PHP%20sometimes%C2%A0can%20be%20tricky.%20I%20haven%27t%20used%20PHP%20on%20Solaris%20since%20my%20time%20at%20AOL%20in%20Dublin%20three%20years%20ago%2C%20so%20I%20de&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;title=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86+-+http://b2l.me/w7g6z&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
