{"id":243,"date":"2009-03-17T13:42:06","date_gmt":"2009-03-17T18:42:06","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=243"},"modified":"2009-03-17T15:44:27","modified_gmt":"2009-03-17T20:44:27","slug":"awstats-on-apache","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2009\/03\/awstats-on-apache\/","title":{"rendered":"AWStats on Apache"},"content":{"rendered":"<p>If you&#8217;ve ever seen an Apache log file, you&#8217;ll notice that it&#8217;s rather long to read.  It&#8217;s not that the log is hard to read, it&#8217;s just full of a lot of useless information.  If you view a website with a browser, the log will show that you connect and retrieve every single file (images are included).  Ouch.<\/p>\n<p>I installed Debian 5.0 Server on an HP DL380 G4 server.  I then did all the updates etc.  I&#8217;m assuming you know how to install apache and how to &#8220;su&#8221; to root.<\/p>\n<p><code>apt-get install awstats<\/code><br \/>\n<code>nano \/etc\/apache2\/awstats.conf<\/code><br \/>\nThis creates a new file called awstats.conf<\/p>\n<blockquote><p>Alias \/awstatsclasses &#8220;\/usr\/share\/awstats\/lib\/&#8221;<br \/>\nAlias \/awstats-icon\/ &#8220;\/usr\/share\/awstats\/icon\/&#8221;<br \/>\nAlias \/awstatscss &#8220;\/usr\/share\/doc\/awstats\/examples\/css&#8221;<br \/>\nScriptAlias \/cgi-bin\/ \/usr\/lib\/cgi-bin\/<br \/>\nScriptAlias \/awstats\/ \/usr\/lib\/cgi-bin\/<br \/>\nOptions ExecCGI -MultiViews +SymLinksIfOwnerMatch<\/p><\/blockquote>\n<p>Save this file and exit back to the shell.<\/p>\n<p><code>nano \/etc\/apache2\/apache2.conf<\/code><\/p>\n<p>Add this to the end of the conf file:<\/p>\n<blockquote><p>Include \/etc\/apache2\/awstats.conf\n<\/p><\/blockquote>\n<p>Save and exit apache.conf.<\/p>\n<p><code>apache2ctl restart<\/code><\/p>\n<p><code>cd \/etc\/awstats<\/code><br \/>\n<code>cp awstats.conf awstats.www.mysite.org.conf<\/code><br \/>\n<code>nano awstats.www.mysite.org.conf<\/code><\/p>\n<p>Search for and edit the following:<\/p>\n<blockquote><p>LogFile=&#8221;\/var\/log\/apache2\/access.log&#8221;<br \/>\nSiteDomain=&#8221;mysite.org&#8221;<\/p><\/blockquote>\n<p>Save the file and exit to the shell.<\/p>\n<p>Now we need to run the script to parse the log files into a stats page:<br \/>\n<code>perl \/usr\/lib\/cgi-bin\/awstats.pl -update -config=www.mysite.org<\/code><\/p>\n<p>If it fails due to permissions:<br \/>\n<code>chmod -R 777 \/var\/log\/apache2<\/code><br \/>\nThen re-run the script<\/p>\n<p>Now check your stats at http:\/\/www.mysite.org\/awstats\/awstats.pl<\/p>\n<p>As long as everything went to plan, the script should also automatically install a cron job to update the stats every 10 minutes.<\/p>\n<p>You can find out by typing the following:<br \/>\n<code>dpkg -L awstats | grep cron<\/code><br \/>\nWhich shows the following:<\/p>\n<blockquote><p>\/etc\/cron.d<br \/>\n\/etc\/cron.d\/awstats<\/p><\/blockquote>\n<p>If you nano the awstats cron, you can edit the times and locations of the scripts.<\/p>\n<p>EDIT!!!<\/p>\n<p>If you&#8217;re using virtual hosts (like I am) and you want each site to have its own stats:<\/p>\n<p>Edit your sites-available default:<br \/>\nnano \/etc\/apache2\/sites-available\/default<\/p>\n<p>Add the following in your VirtualHost:<\/p>\n<blockquote><p>NameVirtualHost 192.168.1.4<br \/>\n<VirtualHost 192.168.1.4><br \/>\n        DocumentRoot &#8220;\/var\/www\/web123&#8221;<br \/>\n        ServerName web123.com<br \/>\n        ServerAlias *.web123.com<br \/>\n        CustomLog \/var\/log\/apache2\/web123.com.log combined<br \/>\n<\/VirtualHost>\n<\/p><\/blockquote>\n<p>Then you&#8217;ll have to create the awstats.web123.com.conf file in \/etc\/awstats<br \/>\ncp \/etc\/awstats\/awstats.conf \/etc\/awstats\/awstats.web123.com.conf<br \/>\nnano \/etc\/awstats\/awstats.web123.com.conf<\/p>\n<p>Change the following:<\/p>\n<blockquote><p>LogFile=&#8221;\/var\/log\/apache2\/web123.com.log&#8221;<br \/>\nLogFormat=1<br \/>\nSiteDomain=&#8221;web123.com&#8221;<br \/>\nHostAliases=&#8221;web123.com www.web123.com localhost 127.0.0.1&#8243;<\/p><\/blockquote>\n<p>This will allow you to use the browser to update the stats if your CRON job is set for long periods of time:<\/p>\n<blockquote><p>AllowToUpdateStatsFromBrowser=1<\/p><\/blockquote>\n<p>And I set this up because I have apache do a DNS lookup on its own:<\/p>\n<blockquote><p>DNSLookup=0<\/p><\/blockquote>\n<p>Then restart apache:<br \/>\n<code>apache2ctl restart<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve ever seen an Apache log file, you&#8217;ll notice that it&#8217;s rather long to read. It&#8217;s not that the log is hard to read, it&#8217;s just full of a lot of useless information. If you view a website with a browser, the log will show that you connect and retrieve every single file (images &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2009\/03\/awstats-on-apache\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">AWStats on Apache<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-243","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=243"}],"version-history":[{"count":4,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/243\/revisions\/245"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}