Post navigation

Host Your Own Hit Counter

Some of the pididu.com pages have a counter on them, like the abacus at the bottom of this page, to show the number of times a page has been viewed.

These counters are hosted locally on my server. This is harder than just linking to a pre-made counter on someone else’s server, but allows more independence from other sites and their tracking. Herewith is how I implemented the counter.

First, I downloaded the source distribution for a counter from muquit.com

The defaults in the source need to be changed to match the structure of the Linux release being used. For Ubuntu 16.04 or Raspbian Stretch, the changes must be made in all four files as follows. The changes must be made in the order shown.

Change all occurences of “/usr/local/etc/Counter” to “/opt/Counter”

Change all occurences of “/usr/local/apache/cgi-bin” to “/usr/lib/cgi-bin”

Change all occurences of “/usr/local” to “/opt”

Here are the source files with those changes already made: Editedwwwcount2.6.tar.gz If you are using Ubuntu or Raspbian, you can use these files directly, rather than bothering with the editing.

Now the counter program must be compiled and installed.

cd ~/Downloads/wwwcount2.6
# I will use individual data files for the counts rather than a database
./build --with-cgi-bin-dir=/usr/lib/cgi-bin --without-database --prefix=/opt/Counter
sudo ./build --install
Continue? y
Do you know the user and group id of httpd's child process? y
Enter user id ... : www-data
Enter group id ... : www-data

Finally, some code must be added to the page being counted. Mr. Muquit’s counter is rich in features, and there are too many to detail here. See his site for how to set things up. But as an example, the following code is what is used for this page. This specifies the file /opt/Count/data/smallproj1.count as where to keep the count, digit style as abacus, 6 digits, and a 6-pixel thick frame of color red. While there are a few fonts included with the source, abacus is not one of them. If you want it, you will need to get it from a site such as Digit Mania.