How to Install Matomo with LAMP Stack on Debian 12

Hello,

In this week’s feature highlight, we look at How to Install Matomo with LAMP Stack on Debian 12

Matomo, formerly Piwik, is a free and open-source web analytics application developed by a team of international developers, that runs on a PHP/MySQL webserver. It tracks online visits to one or more websites and displays reports on these visits for analysis. In this article, we are going to learn how to install Matomo on Ubuntu 22.04. So, let’s get started.

Checkout the Matomo Project Here.

Try this wiki on our VPS. Starting at just $5/month with 24×7 In-house customer support.

Pre-requisites :

  • A system with Debian 12 installed and running.
  • root access to the system.
  • LAMP Stack installed and running, for this, you can refer to one of our guides on installing the LAMP Stack (Apache, MariaDB, and PHP).

Once you’re all set, we’ll proceed with Matomo installation and configuration.

Create Database

Let us begin with creating a Database and a user. We will then grant the required privileges to the user so it can interact with the Database.

mysql -u root

CREATE DATABASE matomo_db;

CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'YOUR-PASSWORD-HERE';

GRANT ALL PRIVILEGES ON matomo_db.* TO 'matomo_user'@'localhost';

FLUSH PRIVILEGES;

QUIT

The above commands will give complete access to the user matomo_user. Replace YOUR-PASSWORD-HERE with a safe and secure password.

Install Let’s Encrypt SSL Certificate

Let’s issue an SSL certificate for the domain for this we will need a snap package for Debian operating system.

We will update and install the snap package on the system:

apt update

apt install -y snapd

snap install core && sudo snap refresh core

Next, with the help of snap, we will install the certbot client which is used to create Let’s Encrypt certificates:

snap install --classic certbot

ln -s /snap/bin/certbot /usr/bin/certbot

Install SSL Certificate

Use the certbot command to issue a Let’s Encrypt certificate. The command will auto-detect the domains available or configured in the vHost configuration:

certbot --apache

Download Matomo

Download Matomo from official website : Click here.

Install the unzip package by following command

apt install unzip

cd /var/www/

wget https://builds.matomo.org/matomo.zip && unzip matomo.zip

rm matomo.zip

cd matomo

mkdir tmp

Setting up File Permissions

Let’s make the folders readable.

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

chmod -R 755 /var/www/matomo

Configuring Apache vHost

Create a new apache configuration file dev.domainhere.info.conf for the domain with the following command:

vi /etc/apache2/sites-available/dev.domainhere.info.conf

Add the following codes:

<VirtualHost *:80>

ServerName dev.domainhere.info
ServerAlias dev.domainhere.info
ServerAdmin admin@dev.domainhere.info
DocumentRoot /var/www/matomo

ErrorLog ${APACHE_LOG_DIR}/dev.domainhere.info_error.log
CustomLog ${APACHE_LOG_DIR}/dev.domainhere.info_access.log combined

<Directory /var/www/matomo/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>

</VirtualHost>

Change dev.domainhere.info with your actual Domain Name.

Now, press the Esc key, and type :wq! and press the Enter key to save and exit the file.

Edit the PHP config filephp.ini using nano or vi,

nano /etc/php/8.1/apache2/php.ini

Add the following lines at the end of the file,

extension=mysqli.so
extension=pdo.so
extension=pdo_mysql.so

Save and exit the file.

Disable the defafult configuration and enable the new site configuration using the following command,

a2dissite 000-default.conf

a2ensite dev.domainhere.info.conf

Now Restart the Apache service and check the status,

systemctl restart apache2

systemctl status apache2

Enable Firewall:

ufw allow 80/tcp

ufw allow 443/tcp

Configuring Matomo

Now open the URL from your browser, this will redirect you to configuring the final parts of the Matomo installation.

https://dev.domainhere.info

Replace the dev.domainhere.info with the actual IP or domain configured on the server.

Input the Database details which was configured earlier. Follow the below steps:

images
images
images
images
images
images
images
images

Now you have successfully installed Matomo with LAMP Stack on Debian 12.

(Visited 26 times, 1 visits today)