01
Before you start
Matomo's official documentation requires, for version 6:
- PHP 8.1 or newer, with the
pdo_mysql or mysqli extension; the gd extension is recommended;
- MySQL 8.0 or newer, or MariaDB 10.6 or newer;
- a web server: Apache, Nginx or another.
Debian 12 and Ubuntu 22.04 or 24.04 ship suitable versions in their repositories. For server size, Matomo recommends at least 2 CPUs, 2 GB of memory and 50 GB of disk for up to 100,000 page views per month, and 4 CPUs, 8 GB and 250 GB for up to one million.
You also need a subdomain, for example stats.example.com, whose A record points to the VPS's IP address, to serve Matomo over HTTPS. First apply the basics from securing a Linux VPS. If the VPS already hosts your websites, Matomo can sit alongside them: see hosting a website on a VPS.
02
Installing from the official archive
Packages. On Debian 12 or Ubuntu, with Apache:
sudo apt update
sudo apt install -y apache2 libapache2-mod-php php-mysql php-gd php-curl php-xml php-mbstring php-cli mariadb-server unzip
sudo ufw allow 80,443/tcp
Database. Create a database and an account that can only access it, as Matomo advises. Open MariaDB with sudo mariadb, then:
CREATE DATABASE matomo;
CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'un-mot-de-passe-solide';
GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Files. Download the latest release and extract it into /var/www: the archive creates a matomo folder.
cd /var/www
sudo wget https://builds.matomo.org/matomo.zip
sudo unzip matomo.zip
sudo rm matomo.zip
sudo chown -R www-data:www-data /var/www/matomo
Apache site. Create /etc/apache2/sites-available/matomo.conf:
<VirtualHost *:80>
ServerName stats.example.com
DocumentRoot /var/www/matomo
<Directory /var/www/matomo>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
AllowOverride All lets the .htaccess files that Matomo creates take effect, blocking access to its sensitive folders such as config and tmp. Enable the site, then get the HTTPS certificate (details in Let's Encrypt certificates with Certbot):
sudo a2ensite matomo
sudo systemctl reload apache2
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d stats.example.com
With Nginx, Matomo publishes a reference configuration in its matomo-org/matomo-nginx repository, which blocks the same folders.
The wizard. Open https://stats.example.com: the wizard checks the system (fix anything it flags in red), asks for the database (server localhost, account matomo, database matomo), creates the superuser account, registers your first website, then shows the tracking code. Choose a strong password for the superuser: it has every right.
03
The Docker option
Matomo publishes an official Docker image, matomo, and a Docker Compose example with MariaDB. You need Docker with Docker Compose (see installing Docker on a VPS). In /opt/matomo, create compose.yml, adapted from the official example:
services:
db:
image: mariadb:lts
command: --max-allowed-packet=64MB
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MARIADB_DATABASE=matomo
- MARIADB_USER=matomo
- MARIADB_PASSWORD=${MARIADB_PASSWORD}
- MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
- MARIADB_AUTO_UPGRADE=1
app:
image: matomo
restart: always
depends_on:
- db
volumes:
- matomo:/var/www/html
environment:
- MATOMO_DATABASE_HOST=db
- MATOMO_DATABASE_ADAPTER=mysql
- MATOMO_DATABASE_TABLES_PREFIX=matomo_
- MATOMO_DATABASE_USERNAME=matomo
- MATOMO_DATABASE_PASSWORD=${MARIADB_PASSWORD}
- MATOMO_DATABASE_DBNAME=matomo
ports:
- 127.0.0.1:8080:80
volumes:
db:
matomo:
Put both passwords in a .env file in the same folder (MARIADB_PASSWORD=… and MARIADB_ROOT_PASSWORD=…), then run sudo docker compose up -d. In the wizard, the database server is called db.
The official example publishes port 8080 on every address; here it only listens on the VPS itself (127.0.0.1), because Docker bypasses UFW firewall rules. HTTPS then comes from a reverse proxy installed on the VPS, for example Nginx Proxy Manager, which forwards stats.example.com to port 8080. If that proxy itself runs in Docker, connect it to the container through a shared Docker network instead.
04
Tracking code, GDPR and the CNIL exemption
The tracking code is a short JavaScript snippet, specific to each website, that the wizard shows at the end of the installation. You can find it again in the administration (cog icon), under the websites section (called "Measurables" in some versions), then "Tracking Code". Paste it on every page you want to measure, just before the </head> tag or in your site's shared header. For WordPress or Ghost (see installing Ghost on a VPS), the slot provided for header code does the job. If no visits show up, first check that the code is really present in your pages' source.
GDPR. Self-hosted, Matomo keeps your visitors' data on your VPS, without passing it to a third party. That does not exempt you from data protection rules: inform your visitors in your privacy policy.
The consent exemption. The CNIL, the French data protection authority, allows some audience measurement tools to be used without asking visitors for consent, under strict conditions. Matomo states, based on its own assessment, that it can qualify if it is configured as described in its dedicated guide (search for "CNIL exemption" in the matomo.org FAQ), with a CNIL compliance mode to switch on. Among the conditions listed: measurement limited to audience statistics, anonymised IP addresses, no cross-site tracking, a limited retention period and a way for visitors to opt out. If a single criterion is missing, the exemption no longer applies: read that guide and the recommendations published on cnil.fr before removing your consent banner.
05
Archiving, backups and updates
Archiving. Matomo builds its reports from raw visits. By default, this runs when someone views the statistics, which gets slow as soon as traffic grows. Matomo recommends a scheduled task that runs core:archive every hour, as the same user as the web server. Create /etc/cron.d/matomo-archive:
5 * * * * www-data /usr/bin/php /var/www/matomo/console core:archive --url=https://stats.example.com/ >> /var/log/matomo-archive.log 2>&1
Create the log file and give it to www-data, then run a first archive by hand to check:
sudo install -o www-data -g www-data -m 640 /dev/null /var/log/matomo-archive.log
sudo -u www-data /usr/bin/php /var/www/matomo/console core:archive --url=https://stats.example.com/
Then disable browser-triggered archiving: in Administration, System, General Settings, set "Archive reports when viewed from the browser" to "No". With Docker, the task runs the same command inside the container: cd /opt/matomo && docker compose exec -T -u www-data app php /var/www/html/console core:archive --url=https://stats.example.com/.
Backups. Matomo asks you to back up the database, the config/config.ini.php file and any plugins installed from the Marketplace, stored in plugins:
sudo mariadb-dump --single-transaction matomo > /root/matomo-$(date +%F).sql
sudo tar czf /root/matomo-fichiers-$(date +%F).tar.gz -C /var/www/matomo config/config.ini.php plugins
Copy these files off the VPS (scp, rsync or external storage).
Updates. Matomo announces new versions in its interface and offers an automatic update: take a backup just before. With Docker, be careful: the image only copies Matomo's files into the volume when the volume is empty. Switching images updates PHP, but not Matomo: also use the update offered in the interface. To be alerted if the analytics site goes down, see Uptime Kuma on a VPS.
06
On CloudFive
CloudFive does not offer managed Matomo: you install it yourself on a VPS, with root access. The Ryzen VPS, from €5.99 per month, is a good fit:
- an AMD Ryzen 9 9950X, with DDR5 memory and NVMe storage, for quickly computed reports and a responsive database;
- root access and a dedicated IP address to point the analytics subdomain at;
- basic anti-DDoS protection included.
Choose memory and disk based on Matomo's recommendations and your traffic, and plan for more if your websites run on the same VPS. If you prefer the Docker option, the Docker VPS page shows which plan to pick for the containers you have in mind. Servers are in France, on our own network, monthly with no commitment, with support in French 7 days a week by ticket, on Discord and by phone.
07
Frequently asked questions
Is Matomo free?
Yes. Matomo is open-source software you can install for free on your own server. You only pay for hosting, and a few Marketplace plugins are paid.
What are the requirements to install Matomo?
For Matomo 6, the official documentation requires PHP 8.1 or newer with pdo_mysql or mysqli, MySQL 8.0 or MariaDB 10.6 at least, and a web server such as Apache or Nginx. It recommends at least 2 CPUs and 2 GB of memory for up to 100,000 page views per month.
Is Matomo exempt from consent under CNIL rules?
The CNIL allows some audience measurement tools to run without consent, under strict conditions. Matomo states it can qualify if configured according to its dedicated guide, with the CNIL compliance mode; check every condition before removing your consent banner.
Why are Matomo reports slow?
By default, Matomo computes its reports when they are viewed. Schedule the core:archive command every hour with cron, as the web server user, then disable browser-triggered archiving in the general settings.
What should I back up on a Matomo installation?
The MySQL or MariaDB database, the config/config.ini.php file and any plugins installed from the Marketplace, in the plugins folder. Copy these backups off the VPS.