How to Setup Matamo in Ubuntu 22.04

| | 2 min read

Matomo, formerly known as Piwik, is a powerful and Free and Open Source web analytics platform that offers website owners a comprehensive insight into their online traffic, user behavior, and digital marketing effectiveness. Diverging from other analytics platforms, Matomo strongly emphasizes user privacy and ensures full data ownership for its users. This makes it an attractive alternative to solutions like Google Analytics, especially for those who prioritize data security and wish to have an on-premise analytics tool. This guide will walk you through the steps to seamlessly install Matomo on an Ubuntu server, enabling you to harness its capabilities and take control of your web analytics journey.

Step-by-Step Guide to Install Matomo on Ubuntu 22.04


  • A system with Ubuntu 22.04 installed and running. [In our case, We have used a Linode VPS with the specification of 4 GB RAM / 2 CPU / 80 GB disk/ Ubuntu 22.04 OS.]
  • Root access to the system.

Matamo installation and configuration

Matomo requires a webserver, PHP, and MySQL database to function. 

Environment Setup

Step 1: Create the user account to setup the virtual host and home directory for Matomo

sudo useradd -s /bin/bash -d /home/matomo -m -G sudo matomo

Step 2: Install the required software

 sudo apt update
sudo apt install apache2 mysql-server-8.0 php-8.1 php8.1-curl php8.1-gd php8.1-mysql php8.1-xml php8.1-mbstring

Step 3:  Set root password for MySQL

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$STRONGPASSWORD';

Step 4: Create the required database user and database for setting up the Matomo

mysql -uroot -p
create database matomodb;
create user 'matomodu'@'%' identified by '$PASSWORD';
grant all privileges on matomodb.* to 'matomodu'@'%';

Step 5: Create the virtual host in Apache


Add the following the lines to the apache configuration file

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  ServerName $DOMAINNAME
  DocumentRoot $PATH
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  <Directory "$PATH">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
RewriteEngine on


Step 6: Create a new user account in the name 'matomo' and set the home directory

sudo useradd -s /bin/bash -d /home/matomo -m -G sudo matomo

Step 7: Switch to the user and create the web and log folders

sudo su matomo
cd /home/matomo
mkdir web 
mkdir logs

Step 8: Download the latest version of Matomo and extract the zip archive to the web folder



Matomo installation

Step 1: Open the domain you have configured in the virtual host file in a browser and you will get the Matomo welcome screen.


Step 2: System Check to check the server requirements


Step 3: Provide the Database details during the installation steps 


Step 4: Provide the Superuser login credentials.


Step 5: You can setup your first website with Matomo

motomo -6

The above steps will complete the setup. Access the site URL again and login with the superuser credentials setup.

motomo -7

Once the installation is complete, you can set up the tracking code provided on your website, and the data will start flowing into Matomo. If you want to use Matomo for importing data from UA, you need to install the UA importer plugin. Follow this article for the details. 

We offer to set up Matomo and enable universal analytics backup as a professional service. Check out our UA to Matomo page for the details