InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Apache tutorials

  • AWStats on Ubuntu
  • ApacheBench - load testing
  • Auth to a location or directory
  • Block directory access using htaccess 404
  • Different expire Headers for multiple images
  • Disable directory listing
  • List loaded modules
  • Log Content-Type in access log
  • Log latency and host in apache log
  • Monitoring using mod_status
  • Python to analyze bots in logs
  • Remove php extension from url
  • egrep and access log
  • log custom data in apache access log
  • mod_rewrite
  • top IP list from access log
 
  • Home
  • > Tutorials
  • > Web Development
  • > Apache

How to install AWStats on Ubuntu Linux

By admin on Nov 27, 2015

AWStats is a powerful and featureful tool to analyze apache access logs. Using AWStats, you can view various stats 404, etc. Here are steps to install AWStats on Ubuntu Linux:

Install AWStats package on Ubuntu Linux

$ sudo apt-get install awstats

To see files in package awstats:

$ dpkg -L awstats

AWStats configuration

Edit awstats config file at location /etc/awstats/awstats.conf.local using sudo. Depending upon you log file name and domain name change the value of LogFile and SiteDomain.

Case 1

You log file is access_log

LogFile="/var/log/apache2/access.log"
SiteDomain="yourdomain.com"

Case 2

You log file is access_log.YYYY-MM-DD

LogFile="/var/log/apache2/access_log.%YYYY-0-%MM-0-%DD-0"
SiteDomain="yourdomain.com"

AWStats crons

As part of the package installation AWStats also installs cron which runs as www-data to populate data in /var/lib/awstats/. To view the cron entries, run the following:

$ cat /etc/cron.d/awstats
MAILTO=root

*/10 * * * * www-data [ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/update.sh

# Generate static reports:
10 03 * * * www-data [ -x /usr/share/awstats/tools/buildstatic.sh ] && /usr/share/awstats/tools/buildstatic.sh

You may want to change MAILTO value to you email address.

AWStats data location

Since cron runs every 10 min, wait for few minutes (max 10 minutes) and you should be able to see data files in /var/lib/awstats/

$ sudo ls -l /var/lib/awstats/
total 24
-rw-rw-r-- 1 www-data www-data 15723 Nov 27 17:10 awstats112015.txt
-rw-rw-r-- 1 www-data www-data  7014 Nov 27 17:10 dnscachelastupdate.hash

AWStats apache configuration

Not setup apache conf by copying and editing sample apache conf present in awstats package.

$ sudo cp  /usr/share/doc/awstats/examples/apache.conf /etc/apache2/conf-enabled/awstats.conf

Replace ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ in awstats.conf with the following line.

ScriptAlias /awstats/awstats.pl   /usr/lib/cgi-bin/awstats.pl

AWStats ui

Now check the config syntax and if everything is fine, then restart apache.

$ sudo apache2ctl configtest
$ sudo apache2ctl restart

Now visit your awstats site at the url /awstats/awstats.pl. Here is how it should appear:
awstats-demo-home-page

Add basic apache auth to AWStats

We should also add auth to AWStats urls. Create an auth files using htpasswd. We’ll create user awstats in file /etc/auth_awstats with desired password.

$ sudo htpasswd -c /etc/auth_awstats awstats

Add the following config in awstats.conf to enable http basic auth:

<LocationMatch /(awstats/awstats.pl|cgi-bin/awstats.pl)>
  AuthType Basic
  AuthName "Restricted Resource"
  AuthBasicProvider file
  AuthUserFile /etc/auth_awstats
  Require valid-user
</LocationMatch>

Note that we added cgi-bin/awstats.pl also in above config. In case your apache server has /cgi-bin/ configured, it may make /cgi-bin/awstats.pl accessible. So we should protect that also.

AWStats – check if auth is working

Restart apache for the config to take effect. Now when you access the url /awstats/awstats.pl, you will see username and password prompt as shown below:
awstats-apache-basic-auth-prompt

Suggested posts:

  1. php preg_match – greedy and lazy regex examples
  2. How to use ssh port forwarding to surf a site from different location
  3. How to migrate your site from one domain to another
  4. Disable directory listing in apache
  5. PHP sort associative array using custom compare function
  6. How to install and monitor memcache for php on Ubuntu Linux
  7. Block directory access using htaccess 404
  8. PHP apc – setup and performance benchmarks on Ubuntu Linux
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Apache, Linux, Tutorials, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress