Matomo with Hiawatha

· klm's blog


Original post is here: eklausmeier.goip.de

For this blog I use the Hiawatha web-server. I wanted to employ a web-analysis tool. For this I chose Matomo. Matomo was called Piwik previously. I already use GoAccess on which I have written in Using GoAccess with Hiawatha Web-Server.

To use Matomo with Hiawatha I had to do the following:

  1. Unzip the matomo.zip file downloaded from Matomo latest
  2. chown -R http:http the unzipped directory
  3. Edit index.php in the matomo directory and add umask(022) directly after <? at the top of the file

Editing index.php will result in below warning, which can be ignored:

1Errors below may be due to a partial or failed upload of Matomo files.
2--> Try to reupload all the Matomo files in BINARY mode. <--
3
4File size mismatch: /srv/http/matomo/index.php (expected length: 712, found: 724)

Point 3 clearly is non-obvious. First I didn't get any further with the installation of Matomo, as Matomo could not create directories. Even when I tried to chmod the directories properly, the new directory had wrong permission and no sub-directories could be created. To verifiy that it was indeed a specific Hiawatha problem with umask I ran:

 1<html>
 2<body>
 3<pre>
 4<?php
 5        printf("umask() = %o\n", umask());
 6        printf("umask() = %o\n", umask(0));
 7        printf("umask() = %o\n", umask(0));
 8?>
 9</pre>
10</body>
11</html>

This confirmed:

1umask() = 117
2umask() = 117
3umask() = 0

Now the question emerged, from where this silly umask came from. Looking at the source code showed that in hiawatha.c the code indeed sets the umask:

1int run_webserver(t_settings *settings) {
2	. . .
3	/* Misc settings
4	 */
5	tzset();
6	clearenv();
7	umask(0117);