How to Install Matomo on Debian 11

how to install matomo on debian 11

In this blog post, we will show you how to install Matomo on Debian 11 OS.

Matomo is a free and open-source web analytics application used for live tracking of website visits. Matomo is written in PHP, and it uses MySQL for storing analytics data. It was known previously as Piwik and, in 2018, was officially renamed Matomo. In this tutorial, we will install Matomo with the LAMP stack.

Installing Matomo on Debian 11 with LAMP stack is very easy, and it may take up to 30 minutes. Let’s get things done!

Prerequisites

  • A server with Debian 11 as OS
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

Update the system packages to the latest versions available. Execute the following command:

sudo apt-get update -y && sudo apt-get upgrade -y

Step 2. Install LAMP Stack

We will start with installing the Apache Web server. To do that, execute the following command:

sudo apt-get install apache2 -y

Once installed, start and enable the service.

sudo systemctl enable apache2 && sudo systemctl start apache2

Check if the service is up and running:

sudo systemctl status apache2

You should receive the following output:

    root@host:~# sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-02-02 10:56:26 CST; 1 day 4h ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 442 (apache2)
      Tasks: 9 (limit: 4675)
     Memory: 27.8M
        CPU: 6.175s
     CGroup: /system.slice/apache2.service

Next, we will install the MariaDB database service. To install it execute the following command:

sudo apt-get install mariadb-server -y

Start and enable the mariadb.service with the following commands:

sudo systemctl start mariadb && sudo systemctl enable mariadb

Check the status of the mariadb.service

sudo systemctl status mariadb

You should receive the following output:

root@host:~# sudo systemctl status mariadb
● mariadb.service - MariaDB 10.5.18 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-02-03 15:55:08 CST; 12s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 5350 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 20 (limit: 4675)
     Memory: 70.3M
        CPU: 724ms
     CGroup: /system.slice/mariadb.service
             └─5350 /usr/sbin/mariadbd

The last of the LAMP stack is the PHP, along with its extensions. First, add the GPG key and the repo with the following commands:

sudo apt -y install lsb-release apt-transport-https ca-certificates 

wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

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

sudo apt-get update -y

Once the PHP key and repo are added, you can install the PHP with extensions using this long command:

sudo apt-get install php8.1 php8.1-common php8.1-curl libapache2-mod-php php8.1-imap php8.1-redis php8.1-cli php8.1-snmp php8.1-xml php8.1-zip php8.1-mbstring php8.1-mysql php-mbstring -y

After successful installation, you can check the PHP version with the following command:

php -v

You should get the following output:

root@host:~# php -v
Created directory: /var/lib/snmp/cert_indexes
PHP 8.2.2 (cli) (built: Feb  3 2023 15:21:45) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.2, Copyright (c), by Zend Technologies

We are ready to proceed with database creation and Matomo installation when the LAMP stack is installed.

Step 3. Create a Matomo database and user

To create a Matomo database, the Matomo user logs in to the MySQL command line with the mysql command and executes the following lines of code one by one:

 CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'YourStrongPasswordHere';
 CREATE DATABASE matomo;
 GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost';
 FLUSH PRIVILEGES;
 EXIT;

Step 4. Install Matomo

Go into the Apache document root directory and download the Matomo installation:

cd /var/www/html/

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

Extract the file and remove the zip folder:

unzip matomo-latest.zip

rm matomo-latest.zip

Set the right permission to matomo directory and files:

cd /var/www/html

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

find . -type d -exec chmod 755 {} \;

find . -type f -exec chmod 644 {} \;

h2>Step 5. Create Apache Virtual Host File

Go into the Apache directory and create a configuration file for the Matomo.

cd /etc/apache2/sites-available/

touch matomo.conf

Open the file, paste the following lines of code, save the file and close it.

<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html/matomo

<Directory /var/www/html/matomo>
AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Enable the Apache configuration for Matomo and rewrite the module.

a2dissite 000-default.conf

sudo a2enmod rewrite

sudo a2ensite matomo.conf

Check the syntax:

apachectl -t

You should receive the following output:

root@vps:~# apachectl -t
Syntax OK

If the syntax is OK, restart the Apache service.

systemctl restart apache2

Step 6. Finish Matomo Installation

Access the URL at http://yourdomain.com. You should see the following screen:

matomo finished installation

Click on the Next button. On the next window, if everything is OK, the system check will pass. Click on the Next button as well:

matomo system check

Fill in the Database name, database user, and password you set in step 3.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

matomo setup database

The tables will be created.

matomo creating tables

In the next window, create the administrator user and set a strong password:

matomo create superuser

Next, set the website name and your URL.

matomo set website name and url

On the next window, Matomo will generate the tracking code that you will need to insert into the code of your website.

matomo javascript tracking code

That’s it; you successfully installed Matomo. Click on the Continue to Matomo button, and you should see the login form.

matomo login form

If you find some difficulties installing the Matomo on Debian 11, you can contact our system admins, who will help you with their expertise. All you need to do is to contact our support via ticket or live chat. We are available 24/7.

PS. If you liked this post on how to install Matomo on Debian 11, please share it with your friends on social networks or simply leave a reply below. Thanks.

1 thought on “How to Install Matomo on Debian 11”

  1. Great tutorial.
    I encountered a problem on my machine on the system check page of matomo: “matomo requires either the mysqli extension or both the PDO and pdo_mysql extensions.”
    I was able to resolve this by running this command:
    apt-get install php-mysql

    Reply

Leave a Comment