Skip to content

matomo | Cheatsheet

Matomo, formerly Piwik, is the most common free and open source web analytics application to track online visits to one or more websites and display reports on these visits for analysis.


Requirements

apt install mutt git cmake make mysql-server unzip wget php php-fpm php-curl php-gd php-cli \
php-mysql php-xml php-mbstring geoip-bin geoip-database libapache2-mod-geoip \
libgeoip1 libmaxminddb-dev apache2-dev

/etc/init.d/apache2 restart

Installation

wget https://builds.matomo.org/matomo-latest.zip -P /var/www/

cd /var/www
unzip matomo-latest.zip
rm matomo-latest.zip How\ to\ install\ Matomo.html

chown -R apache:apache /var/www/matomo

find /var/www/matomo/tmp -type f -exec chmod 644 {} \;
find /var/www/matomo/tmp -type d -exec chmod 755 {} \;
find /var/www/matomo/tmp/assets/ -type f -exec chmod 644 {} \;
find /var/www/matomo/tmp/assets/ -type d -exec chmod 755 {} \;
find /var/www/matomo/tmp/cache/ -type f -exec chmod 644 {} \;
find /var/www/matomo/tmp/cache/ -type d -exec chmod 755 {} \;
find /var/www/matomo/tmp/logs/ -type f -exec chmod 644 {} \;
find /var/www/matomo/tmp/logs/ -type d -exec chmod 755 {} \;
find /var/www/matomo/tmp/tcpdf/ -type f -exec chmod 644 {} \;
find /var/www/matomo/tmp/tcpdf/ -type d -exec chmod 755 {} \;
find /var/www/matomo/tmp/templates_c -type f -exec chmod 644 {} \;
find /var/www/matomo/tmp/templates_c -type d -exec chmod 755 {} \;

Mysql

This is just examples, don't use root or your real name for security reasons

create database matomo;
CREATE USER 'root'@'%' IDENTIFIED BY 'password';
GRANT PRIVILEGE ON *.** TO 'wuseman'@'%';
GRANT ALL PRIVILEGES ON *.* TO 'wuseman'@'%';
FLUSH PRIVILEGES;
quit;

Configure subdomain

cat<< EOF > /etc/apache2/vhosts.d/stats.nr1.nu.conf
<VirtualHost *:80>
ServerAdmin wusema@nr1.nu
ServerName stats.nr1.nu
DocumentRoot /var/www/matomo/

    <Directory /var/www/matomo>
       DirectoryIndex index.php
       Options FollowSymLinks
       AllowOverride All
       Require all granted
    </Directory>

    <Files "console">
       Options None 
       Require all denied
    </Files>

    <Directory /var/www/matomo/misc/user>
       Options None 
       Require all granted
    </Directory>

    <Directory /var/www/matomo/misc>
       Options None 
       Require all denied
    </Directory>

    <Directory /var/www/matomo/vendor>
       Options None 
       Require all denied
    </Directory>

    ErrorLog /var/log/apache2/stats.nr1.nu_matomo_error.log
    CustomLog /var/log/apache2/stats.nr1.nu_matomo_access.log combined
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =stats.nr1.nu [OR]
    RewriteCond %{SERVER_NAME} =stats.nr1.nu
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
EOF

Archive the Reports (default)

5 * * * * /usr/bin/php /var/www/matomo/console core:archive --url=https://stats.nr1.nu > /dev/null

Archive the Reports (not default)

cat <<! > /etc/cron.d/matomo-archive
MAILTO="youremail@example.com"
5 * * * * www-data /usr/bin/php /var/www/matomo/console core:archive --url=http://example.org/matomo/ > /home/example/matomo-archive.log
!

Create Signed SSL Certificates

certbot -d stats.nr1.nu --apache
/etc/init.d/apache2 restart

After following install Matomo, browse to: http://localhost/matomo

Configure Matomo via console

List available plugins

/var/www/matomo/console plugin:list

Core update

/var/www/matomo/console core:update

Disable two-factor authentication for a user.

  • Useful if a user loses the device that was used for two-factor authentication. After it was disabled, the user will be able to set it up again
/var/www/matomo/console  twofactorauth:disable-2fa-for-user

Watch logs in realtime

/var/www/matomo/console log:watch
/var/www/matomo/console core:version

Test mail setup

/var/www/matomo/console core:test-email wuseman@nr1.nu

Archiving stats

/usr/bin/php /var/www/matomo/console core:archive --url=https://stats.nr1.nu

Disable 2FA from commandline

/var/www/matomo/console twofactorauth:disable-2fa-for-user --login=user

Resources