Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

How to Install Matomo on Debian 11

Last Updated: Tue, Mar 1, 2022
Debian Server Apps Web Servers

Introduction

Matomo, formerly known as Piwik, is a free and open-source web-based analytics application. It tracks online traffic on websites and gives detailed reports on visits, clicks, and other metrics. This information is useful to business owners of e-commerce platforms analysis. Like Google Analytics, Matomo ships with many features, including full control of your data, customizable dashboard, content tracking, geolocation support, reporting API, Google AdWords, and Facebook Ads, among other features.

This article explains how to install Matomo on Debian 11 server.

Prerequisites

Perform the following steps first:

Step 1. Install LAMP Server

Update the system package list.

$ sudo apt update

Install the required packages.

$ sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2

Add PHP repository to the APT.

$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list

Download and add the repository keys.

$ wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -

Update the system package list.

$ sudo apt update

Install PHP 8.0, MySQL server, Apache server, and more modules.

$ sudo apt install apache2 mariadb-server php8.0 libapache2-mod-php8.0 php8.0-mysql php8.0-curl php8.0-xml php8.0-zip php8.0-mbstring php8.0-intl php8.0-opcache php8.0-imagick php8.0-gd php8.0-cli php8.0-fpm libapache2-mod-fcgid wget unzip -y

Enable MySQL to start automatically on a reboot.

$ sudo systemctl enable mysql

Enable Apache to start automatically on a reboot.

$ sudo systemctl enable apache2

Step 2. Create Matomo Database

Run mysql_secure installation script to set up MySQL security. This helps you prevent remote logins to your database server.

$ sudo mysql_secure_installation

When prompted, answer the questions as shown below:

  • Enter current password for root (enter for none): Press ENTER.
  • Switch to unix_socket authentication? Press N, then ENTER.
  • Change the root password? Press Y, then ENTER.
  • Remove anonymous users? Press Y, then ENTER.
  • Disallow root login remotely? Press Y, then ENTER.
  • Remove test database and access to it? Press Y, then ENTER.
  • Reload privilege tables now? Press Y, then ENTER.

Log in to MySQL shell. At the password prompt, enter your password to continue.

$ sudo mysql -u root -p

Create a MySQL database named matomo.

CREATE DATABASE matomo;

Create a database user named matomouser with a password.

CREATE USER 'matomouser'@'localhost' IDENTIFIED BY 'StrongPassword';

Grant the user full access to the database.

GRANT ALL ON matomo.* TO 'matomouser'@'localhost' WITH GRANT OPTION;

Save the changes made on the database.

FLUSH PRIVILEGES;

Exit the MySQL shell.

exit;

Step 3. Install Matomo

Download the latest version of Matomo. To find more versions of the installation files, please visit the official download page.

$ wget https://builds.matomo.org/matomo-latest.zip

Extract the downloaded archive.

$ sudo unzip matomo-latest.zip

Move the extracted directory to the web root directory.

$ sudo mv matomo /var/www/

Delete the downloaded archives.

$ sudo rm matomo-latest.zip

Change ownership of the installation directory.

$ sudo chown -R www-data:www-data /var/www/matomo

Change access permissions for the directory.

$ sudo chmod -R 755 /var/www/matomo

Step 4. Configure Apache2

Allow port 80 through the firewall.

$ sudo ufw allow 80

Disable Apache default configuration file.

$ sudo a2dissite 000-default.conf

Create an Apache virtual host configuration file named matomo.conf.

$ sudo nano /etc/apache2/sites-available/matomo.conf

Add the following code to the file. Save and close the file.

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    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 ${APACHE_LOG_DIR}/matomo_error.log
    CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined

</VirtualHost>

Enable Matomo Apache configuration file.

$ sudo a2ensite matomo.conf

Enable Apache rewrite mode.

$ sudo a2enmod rewrite

Restart Apache service.

$ sudo systemctl restart apache2

Step 5. Access Matomo Web Interface

To access Matomo via the web, go to your browser and visit http://ServerIP/. For example:

http://192.0.2.10/

Conclusion

You have installed Matomo on your Debian 11 server. To complete installation, access the installation wizard, connect to your database using your credentials, and set up an administrator account. Next, configure the site settings and log in to the administrator dashboard. To learn more about using Matomo, go to the official documentation page.

Want to contribute?

You could earn up to $600 by adding new articles.

La versión española del presente sitio web es una traducción realizada únicamente con fines informativos, y la versión inglesa prevalecerá.