πŸ‘ˆπŸΌ πŸ•ΈπŸ’ πŸ‘‰πŸΌ
Skip to main content

Arne Govaerts

Running Known with Matomo and Caddy #2

2 min read

Continuing from the previous post, let's install Matomo.

First add a new database:

sudo mysql -u root -p
mysql> CREATE DATABASE db_name;
mysql> GRANT ALL ON db_name.* TO 'username' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> quit

Followed by adding the following to /etc/caddy/Caddyfile:

matomo.example.com {
    root * /var/www/matomo.example.com

    encode zstd gzip

    @php path_regexp php ^/(.*\.php)$
    @php_allowed path_regexp php_allowed ^(/(index|matomo|js/index|plugins/HeatmapSessionRecording/configs)\.php)$
    handle @php {
        handle @php_allowed {
            php_fastcgi unix//run/php/phpx.x-fpm.sock
        }
        respond "Access Denied" 403
    }

    file_server
    try_files {path} /index.php?query
}

And restart Caddy.

Now we can install Matomo:

sudo mkdir -p /var/www/matomo.example.com
cd /var/www/matomo.example.com
sudo wget https://builds.matomo.org/matomo.zip
sudo unzip matomo.zip
sudo rm matomo.zip
mv matomo/* .
rmdir matomo
sudo chown -R www-data:www-data /var/www/matomo.example.com

Open your browser, follow a few extra steps et voila: Matomo is up and running.

Extra: Use the Matomo for Known plugin

To easily use Matomo (self-hosted or not) in combination with Known, you can install the Matomo for Known plugin (disclaimer: I made it).

This can be done using Composer: composer require argovaerts/known-matomo

In case you want to see the source: It's hosted at Codeberg.