Installation of Matomo (Piwik) on VPS: High-Performance Analytics with Nginx, PHP, and MySQL
TL;DR
In this detailed guide, we will step-by-step set up Matomo (formerly Piwik) – a powerful, open-source web analytics platform – on your Virtual Private Server (VPS). You will learn how to install and configure Nginx as a web server, PHP-FPM for dynamic content processing, and a MySQL/MariaDB database for storing analytical data. The result will be a high-performance and fully controlled analytics system, ensuring complete data privacy and independence from third-party services.
- Full installation of Matomo 5.x on Ubuntu 24.04 LTS.
- Configuration of Nginx 1.28+ as a web server.
- Setting up PHP 8.3/8.4 with FPM for optimal performance.
- Using MySQL 8.x or MariaDB 11.x for data storage.
- Enabling HTTPS with Certbot for a secure connection.
- Recommendations for backups, maintenance, and troubleshooting.
What we are setting up and why
In this guide, we will focus on deploying Matomo (formerly known as Piwik) – a powerful and flexible open-source web analytics platform. Matomo allows you to collect, analyze, and visualize data about your website or application visitors, providing deep insights into their behavior. Unlike many cloud solutions, Matomo gives you full control over your data, its privacy, and storage, which is especially important given the growing requirements for GDPR, CCPA, and other data protection regulations.
Ultimately, you will get a fully functional, high-performance analytics system running on your own VPS. This means that all data about your users will be stored on your server, under your full control, without being transferred to third parties. This is an ideal solution for those who value privacy, data security, and want to avoid subscription fees for cloud services, especially with multiple projects or high traffic volumes.
There are several alternatives to Matomo on the market. The most well-known is Google Analytics, which offers broad functionality but requires data transfer to the Google cloud. There are also cloud-managed versions of Matomo (Matomo Cloud), which relieve you of infrastructure concerns but are usually more expensive and still involve data storage with a provider. The choice of self-hosted Matomo on a VPS is driven by several key advantages: full data ownership, customization and integration capabilities, scalability to your needs, and often a lower total cost of ownership in the long run, especially for projects with high traffic or strict privacy requirements.
What VPS config is needed for this task
Choosing the right VPS for Matomo is critical to ensure stable operation and fast report loading. Matomo, especially with large data volumes and frequent requests, can be resource-intensive. Below are the minimum and recommended requirements for typical Matomo usage scenarios in 2026.
Minimum Requirements (for small websites, up to 10,000 visits per day):
- CPU: 2 cores (e.g., Intel Xeon E5 or AMD EPYC).
- RAM: 4 GB DDR4.
- Disk: 100 GB NVMe SSD. NVMe significantly speeds up database and Matomo file operations.
- Network: 200 Mbit/s, unlimited traffic or with a large reserve (at least 1 TB/month).
- OS: Ubuntu 24.04 LTS (or similar Linux distribution).
Recommended VPS Plan (for medium websites, up to 100,000 visits per day, or multiple websites):
- CPU: 4 cores (modern Intel/AMD).
- RAM: 8-16 GB DDR4. More RAM will allow the system to cache more data, speeding up reports.
- Disk: 250-500 GB NVMe SSD. It is important to have a reserve for database growth.
- Network: 500 Mbit/s – 1 Gbit/s, unlimited traffic.
For deploying Matomo with the specified characteristics, you can consider a VPS with the specified characteristics. It is important to ensure that the chosen provider offers stable performance and reliable support.
When a dedicated server is needed, not a VPS
A dedicated server becomes necessary if your project has very high traffic (hundreds of thousands or millions of visits per day), requires maximum performance, full control over hardware, or specific hardware configurations (e.g., RAID arrays for the database). Matomo can generate very large volumes of data, and at a certain stage, not only the CPU or RAM but also the disk subsystem can become a bottleneck, which can be configured more flexibly on a dedicated server. For such scenarios, you should consider a suitable dedicated server.
Location: what it affects
- Latency: The closer the server is to your primary audience, the faster Matomo will load for your users and the faster data will be collected.
- Legislation: The server's location determines the applicable data protection laws. If your audience is in the EU, hosting the server in the EU can simplify GDPR compliance.
- Availability: Choose locations with reliable data centers and good connectivity.
It is optimal to choose a location that is geographically close to most of your visitors to minimize delays in collecting and displaying analytical data.
Server Preparation
Before proceeding with the installation of Matomo and related software, you need to perform basic configuration of your VPS. We will use Ubuntu 24.04 LTS as the operating system, as it offers excellent stability and up-to-date software. It is assumed that you have already connected to the server via SSH using the root account.
1. System Update
Always start by updating the package list and the system itself to ensure you have the latest software versions and security patches installed.
sudo apt update && sudo apt upgrade -y
This command updates the package indexes and then installs all available updates without prompting for confirmation.
2. Creating a New User with Sudo Privileges
Working under the root account is insecure. Let's create a new user and grant them sudo privileges.
# Replace 'youruser' with the desired username
sudo adduser youruser
sudo usermod -aG sudo youruser
adduser will create a new user and prompt for a password and additional information. usermod -aG sudo will add the user to the sudo group, allowing them to execute commands with elevated privileges.
3. Setting up SSH Key Authentication
Using SSH keys is much more secure than passwords. If you haven't set it up yet, do it now. Generate a key on your local machine (if you don't have one):
# On your local machine
ssh-keygen -t ed25519 -C "[email protected]"
Then copy the public key to the server for your new user. Replace youruser and your_vps_ip with your details:
# On your local machine
ssh-copy-id youruser@your_vps_ip
Now you can disconnect from root and connect as youruser. After a successful connection, disable password authentication for root and, possibly, for all users to enhance security. Edit the file /etc/ssh/sshd_config:
sudo nano /etc/ssh/sshd_config
Find and change the following lines (or add them if missing):
PermitRootLogin no
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
Save changes (Ctrl+O, Enter) and exit (Ctrl+X). Restart the SSH service:
sudo systemctl restart sshd
Important: Make sure you can log in with an SSH key before disabling PermitRootLogin and PasswordAuthentication. Otherwise, you risk losing access to the server.
4. Installing and Configuring the Firewall (UFW)
UFW (Uncomplicated Firewall) is a convenient utility for managing iptables. Let's configure it to allow SSH, HTTP, and HTTPS.
sudo apt install ufw -y # Install UFW
sudo ufw default deny incoming # Deny all incoming by default
sudo ufw default allow outgoing # Allow all outgoing by default
sudo ufw allow ssh # Allow SSH (port 22)
sudo ufw allow http # Allow HTTP (port 80)
sudo ufw allow https # Allow HTTPS (port 443)
sudo ufw enable # Enable UFW
sudo ufw status verbose # Check status
After enabling UFW, make sure you can still connect via SSH. If SSH is running on a non-standard port, replace sudo ufw allow ssh with sudo ufw allow 1234/tcp (where 1234 is your port).
5. Installing Fail2Ban
Fail2Ban scans server logs (e.g., SSH, web server) for suspicious activity (multiple failed login attempts) and temporarily or permanently blocks IP addresses of attackers.
sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
For basic Fail2Ban configuration, you can copy the default configuration file:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
In the jail.local file, you can configure parameters such as bantime (ban time), findtime (period during which failed attempts are considered), and maxretry (maximum number of attempts). Ensure that sections for sshd and nginx-http-auth (needed later) are enabled (enabled = true). Restart Fail2Ban after changes:
sudo systemctl restart fail2ban
6. Installing Basic Utilities
Let's install a few useful utilities that may come in handy during the installation process and for monitoring.
sudo apt install git curl wget htop unzip -y
Now your server is ready for the installation of the core software for Matomo.
Software Installation — Step-by-Step
Now that the server is prepared, let's proceed with installing the necessary software: Nginx (web server), PHP-FPM (PHP processor), MySQL/MariaDB (database), and finally, Matomo itself. We will focus on the current software versions for 2026.
1. Nginx Installation
Nginx will act as a high-performance web server. Ubuntu 24.04 LTS usually comes with a sufficiently recent version of Nginx.
sudo apt install nginx -y # Install Nginx
sudo systemctl enable nginx # Enable Nginx autostart
sudo systemctl start nginx # Start Nginx
sudo ufw allow 'Nginx Full' # Allow HTTP/HTTPS in UFW for Nginx
sudo ufw delete allow 'Nginx HTTP' # Delete old HTTP rules, if any
sudo ufw delete allow 'Nginx HTTPS' # Delete old HTTPS rules, if any
sudo ufw delete allow http # Delete HTTP rule, if any
sudo ufw delete allow https # Delete HTTPS rule, if any
sudo ufw reload # Reload UFW rules
Check Nginx status:
sudo systemctl status nginx
You should see the status active (running).
2. PHP-FPM and Required Extensions Installation
Matomo is written in PHP. We will need PHP 8.3 or 8.4 (current versions for 2026) with PHP-FPM (FastCGI Process Manager) for efficient Nginx request processing. Let's install the necessary extensions.
sudo apt install php8.3-fpm php8.3-mysql php8.3-cli php8.3-gd php8.3-curl php8.3-xml php8.3-mbstring php8.3-intl php8.3-zip php8.3-opcache php8.3-dom -y
This command will install PHP 8.3 FPM, the MySQL driver, the CLI version of PHP, as well as important extensions for Matomo: GD (for graphs), cURL (for HTTP requests), XML/DOM (for XML processing), Mbstring (for multibyte strings), Intl (for internationalization), Zip (for archives), and Opcache (for accelerating PHP scripts).
Enable and start PHP-FPM:
sudo systemctl enable php8.3-fpm
sudo systemctl start php8.3-fpm
Check PHP-FPM status:
sudo systemctl status php8.3-fpm
You should see the status active (running).
3. MySQL/MariaDB Installation
Matomo requires a database to store all analytical information. We will install MariaDB Server 11.x (a modern alternative to MySQL).
sudo apt install mariadb-server -y # Install MariaDB Server
sudo systemctl enable mariadb # Enable MariaDB autostart
sudo systemctl start mariadb # Start MariaDB
Run the MariaDB secure installation script to enhance security:
sudo mysql_secure_installation
Follow the instructions: set a password for the database root user, remove anonymous users, disallow remote root login, and remove the test database. Answer Y to all questions.
Create a database and user for Matomo:
sudo mysql -u root -p
Enter the password you set for the MySQL root user. Then execute the following SQL commands. Replace matomo_user and your_strong_password with your own values.
CREATE DATABASE matomo_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON matomo_db. TO 'matomo_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
These commands create the matomo_db database, the matomo_user user with the specified password, and grant them all necessary access rights to this database.
4. Downloading and Installing Matomo
Let's download the latest stable version of Matomo (Matomo 5.x is assumed for 2026) from the official website and place it in a suitable directory.
cd /tmp
wget https://builds.matomo.org/matomo.zip # Download the latest version of Matomo
sudo mkdir -p /var/www/matomo # Create directory for Matomo
sudo unzip matomo.zip -d /var/www/matomo # Unpack to target directory
sudo chown -R www-data:www-data /var/www/matomo # Set correct permissions
sudo find /var/www/matomo -type d -exec chmod 755 {} \; # Permissions for directories
sudo find /var/www/matomo -type f -exec chmod 644 {} \; # Permissions for files
rm matomo.zip # Delete archive
Setting www-data:www-data permissions is critically important, as the web server (Nginx) and PHP-FPM will operate under this user. This allows Matomo to create and modify necessary files (e.g., cache, logs).