Stats are important—especially to the number-crunchers who dictate your IT budget. AWStats will help you know the stats associated with your websites.
If you're a network or web admin, you like stats. Of course you do. And when the higher ups call a meeting and want numbers, you need to have them. That's when tools like AWStats come into play. AWStats is an open source web analytics software that can give you all the stats you need for your websites.
Ah, analytics—a word every member of the business nation loves to use in a sentence. With good reason. Today's businesses need numbers to crunch. With a tool like AWStats, you get plenty of numbers. But how do you install AWStats?
I'm going to show you.
I will demonstrate on Ubuntu Server 18.04 and will assume you already have your full-blown Apache stack up and running (with your site(s) configured and working). Outside of that, you'll need a user account with sudo privileges. That's it. You're ready to work.
The installation of AWStats is actually quite simple. Open a terminal window (or log into your Ubuntu machine) and issue the following command:
sudo apt install awstats libgeo-ip-perl libgeo-ipfree-perl
That's it for the installation.
Note: I'm going to demonstrate using the old example.com. You will substitute your domain in for that.
The first configuration file is awstats.conf. We need to make a copy of that file, adding our domain name. Back at the terminal window, issue the command (substituting in your domain name):
sudo cp /etc/awstats/awstats.conf /etc/awstats/awstats.example.com.conf
In that file, make sure to edit the following lines to reflect these changes:
LogFormat=1 SiteDomain="example.com" HostAliases="localhost 127.0.0.1 example.com" AllowFullYearView=3 AllowAccessFromWebToFollowingIPAddresses="127.0.0.1 192.168.1.0-192.168.1.255" LoadPlugin="tooltips" LoadPlugin="graphgooglechartapi" LoadPlugin="geoipfree"
As for the plugins, you can view information on what's available from the official AWStats Plugins page. From that list, you can add any plugin to the configuration file you need. If you need to allow access to AWStats from specific IP addresses, make sure to configure that with the AllowAccessFromWebToFollowingIPAddresses option.
Save and close that file.
There is one more configuration file to modify. Issue the command:
sudo nano /etc/awstats/awstats.conf.local
Make sure this file contains the lines:
SiteDomain="example.com" HostAliases="localhost 127.0.0.1 example.com"
Modify the above lines to fit your needs and then save/close the file.
Remove existing data
At this point, an AWStats cronjob will have already run and failed. Why did it fail? Permissions (we'll get to that). Because of this failure, we need to remove the data added to AWStats. To do this, issue the following two commands:
sudo mv /etc/cron.d/awstats /root sudo rm /var/lib/awstats/*
The first command moves the cron job file, so it won't run (we'll move it back later). The second command removes any data that was added by the failed cronjob.
Now we can adjust the permissions, so the AWStats cron job won't fail. To do this, you need to issue the following three commands:
sudo chgrp www-data /var/log/apache2 /var/log/apache2/*log /var/log/apache2/access.log sudo chmod 755 /var/log/apache2 sudo chmod 644 /var/log/apache2/*
Next you'll need to modify another configuration file, this time for the Apache logrotate functionality. Issue the command:
sudo nano /etc/logrotate.d/apache2
In that file, look for the line that starts with:
Make sure the above line looks exactly like this:
create 640 root www-data
Save and close that file.
It's time to move that cronjob back. Do this with the command:
sudo mv /root/awstats /etc/cron.d
Now that AWStats is installed and functioning properly, it's time to configure Apache. Remember, I'm demonstrating with example.com, so you'll want to change this configuration according to your needs.
Open the Apache virtual host file for editing with the command:
sudo nano /etc/apache2/sites-available/example.com.conf
Add the following lines to the bottom of the file (above the tag):
Alias /awstatsclasses "/usr/share/awstats/lib/" Alias /awstats-icon/ "/usr/share/awstats/icon/" Alias /awstatscss "/usr/share/doc/awstats/examples/css" ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ ScriptAlias /awstats/ /usr/lib/cgi-bin/ Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Save and close that file. Enable the CGI module with the command:
sudo a2enmod cgi
Finally, restart Apache with the command:
sudo systemctl restart apache2
Launch your browser
Open your browser and point it to http://SERVER/cgi-bin/awstats.pl (where SERVER is either the IP address or domain of your hosting server). You should see the AWStats page, with newly added data. If you see no data, wait about 10 minutes (which is how often the cronjob runs) and data will appear (Figure A).
Enjoy those numbers
You should now have the ability to report, with more than enough data, about those demanding numbers on the sites you manage. Enjoy that data.
- How to install CA certificates in Ubuntu server (TechRepublic)
- How to create a ZFS storage pool on Ubuntu Server 18.04 (TechRepublic)
- How to install the OpenVAS security audit tool on Ubuntu Server 18.04 (TechRepublic)
- How to set the AppArmor mode for a service in Ubuntu Server (TechRepublic)
- Ubuntu Server (64-bit) (ZDNet)
- DevOps: A cheat sheet (TechRepublic)
- 10 free alternatives to Microsoft Word and Excel (TechRepublic download)
- The 10 most important iPhone apps of all time (Download.com)
- It takes work to keep your data private online. These apps can help (CNET)
- Programming languages and developer career resources coverage (TechRepublic on Flipboard)