How to Install Matomo with LAMP Stack on Ubuntu 22.04

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 24x7 In-house customer support.

Pre-requisites :

  • A system with Ubuntu 22.04 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



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



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 && unzip


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 for the domain with the following command:

vi /etc/apache2/sites-available/

Add the following codes:

<VirtualHost *:80>

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


Change 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,

Save and exit the file.

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

a2dissite 000-default.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.

Replace the with the actual IP or domain configured on the server.

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

Now you have successfully installed Matomo with LAMP Stack on Ubuntu 22.04.