Introduction
In cPanel, AWstats is not displaying the correct stats for the last few days, weeks, or months for a domain.
Procedure
The Awstats feature stores existing statistics data in .txt extension files within the directory path /home/$user/tmp/awstats/ where $user represents the cPanel account username. Since the Awstats service is unable to import logs older than the current ones present in the TXT file, you must move the related files out of the way.
Please note that doing so completely removes the statistics data and so this should only be done if you have existing logs to re-import any data that would be removed.
After moving the TXT file, you then want to copy and extract the related logs zip file from /home/$user/logs. Then, using the Awstats.pl tool you can manually import the months you need, oldest logs first. You'll need to repeat this process for each domain and its SSL variants.
Please note: You’ll need to change "$username" and "domain.tld" to the real username and website name for the account you want to import. Also, make sure to change the Month and Year to the correct month and year that you want to use.
- Make a backup folder for AWStats.
mkdir -pv /root/awstats_backup/$username
- Navigate to one the directories in the user's home folder.
cd /home/$username/tmp/awstats
- If you are importing SSL data.
cd /home/$username/tmp/awstats/ssl
- Copy the log file you want to populate into AWStats.
sudo -u $username cp ../../logs/$username/domain.tld-Month-Year.gz ./
- Move the old txt files.
mv -v awstats{date}.txt /root/awstats_backup/$username - Use gunzip and extract the log file.
gunzip domain.tld-Month-Year.gz
- Finally, populate the log file using the awstats.pl tool.
For HTTP
sudo -u $username /usr/local/cpanel/3rdparty/bin/awstats.pl -config=domain.tld -LogFile=/home/$username/tmp/awstats/domain.tld-Month-Year
For HTTPSsudo -u $username /usr/local/cpanel/3rdparty/bin/awstats.pl -config=domain.tld -configdir=/home/bonecanc/tmp/awstats/ssl -LogFile=/home/$username/tmp/awstats/domain.tld-Month-Year
- Move the existing data back to the user's awstats folder.
cp -a /root/awstats_backup/$username/awstats$date.$domain.tld.txt /home/$username/tmp/awstats/ssl
- Repeat these steps for each user and domain that needs to be imported.