How to install awstats on CentOS

We have known how to install awstats in a control panel like zPanel(Sentora), but how to install awstats in a resource limited VPS such as NAT vps without a control panel?

First, download the awstats package.

Install the rpm package:awstats-7.4-1.noarch.rpm
If you see the following error:

error: Failed dependencies:
perl(LWP::UserAgent) is needed by awstats-7.4-1.noarch

Please install the perl-libwww-perl package first:

yum install perl-libwww-perl

Second, configure awstats by running the awstats_configure.pl script:

cd /usr/local/awstats/tools

perl awstats_configure.pl

You will be asked to input the following information:

the Apache config file path: /etc/httpd/conf/httpd.conf

awstats_configure.pl will add several lines to that file.

—–> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ?
type “y” to continue.

Input the domain name of your website such as domainhostseotool.com to create a config file.

Input the directory name to store the config file, the default directory is /etc/awstats/

the config file is now created and saved as /etc/awstats/awstats.domainhostseotool.com.conf
—–> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=domainhostseotool.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now

You can then manually update your statistics for ‘domainhostseotool.com’ with command:
> perl awstats.pl -update -config=domainhostseotool.com
You can also read your statistics for ‘domainhostseotool.com’ with URL:
> http://localhost/awstats/awstats.pl?config=domainhostseotool.com

awstats_configure.pl now ends leaving a problematic config file.

If everything is ok, you can visit the awstats report via http://domainhostseotool.com/awstats/awstats.pl?config=domainhostseotool.com. But since the configuration is now correct at present, you will get the following error:

Error: AWStats database directory defined in config file by ‘DirData’ parameter (/var/lib/awstats) does not exist or is not writable.

Setup (‘/etc/awstats/awstats.domainhostseotool.com.conf’ file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in ‘docs’ directory).

It seems we should create a directory  /var/lib/awstats and make it writable to save the awstats analysis files. After doing that, you will see the beautiful awstats analysis report. But the report has no real data in it now because awstats has not anaylized the log data yet and /var/lib/awstats is empty now. According to official manual, we should let awstats process the log file and generate the analysis files by running the following script:

perl awstats.pl -config=domainhostseotool.com -update

But the system complains  it cannot find the script awstats.pl. In fact, you should cd to /usr/local/awstats/wwwroot/cgi-bin/ to execute that script. Now you will get the following error:

Create/Update database for config “/etc/awstats/awstats.domainhostseotool.com.conf” by AWStats version 7.4 (build 20150714)
From data in log file “/var/log/httpd/mylog.log”…
Error: Couldn’t open server log file “/var/log/httpd/mylog.log” : No such file or directory
Setup (‘/etc/awstats/awstats.domainhostseotool.com.conf’ file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in ‘docs’ directory).

This is due to the incorrect log file path specified in the config file. You should change it to the actual log file (produced by Apache) for the website. Now the script can run normally, and here is the output:

Create/Update database for config “/etc/awstats/awstats.domainhostseotool.com.conf” by AWStats version 7.4 (build 20150714)
From data in log file “/var/www/domainhostseotool.com/access.log”…
Phase 1 : First bypass old records, searching new record…
Searching new records from beginning of log file…
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)…
Jumped lines in file: 0
Parsed lines in file: 18
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 15 corrupted records,
Found 0 old records,
Found 3 new qualified records.

The so called awstats database is actually a file which is generated by analyzing the log file, and saved in /var/lib/awstats/ with the file name as awstats042016.domainhostseotool.com.txt.

Now refresh the awstats report in the browser, and you will see the actual data. You see, manually running the script in the shell to analyze the log file and see the updated report in the browser is not convenient. Fortunately, you can set the parameter AllowToUpdateStatsFromBrowser in the config file to 1 so that you  can update the report directly from the browser. If you see the error complaining the file in /var/lib/awstats/ is not writable, you should change the owner/group of /var/lib/awstats/ to apache because it is the httpd process that will write to the directory.

 

 

 

 

 

 

 

 

 

 

 

Posted in tips of hosting