Operating System Ubuntu

How to Install Matomo (formerly Piwik) on Ubuntu 26.04 LTS

Piwik is now Matomo. Install it on Ubuntu 26.04 LTS with Apache, MariaDB and PHP, secure it with HTTPS and schedule report archiving.

Piwik was renamed Matomo in January 2018, and the project is actively developed under that name; the current stable series is Matomo 5. This guide installs self-hosted Matomo on Ubuntu 26.04 LTS with Apache, MariaDB and PHP from the Ubuntu repositories, sets up the hourly report-archiving cron job and notes where Ubuntu 24.04 LTS differs. Ubuntu 14.04 is long out of standard support and should not be used for a new installation.

At the end you will have Matomo answering on https://stats.example.com, ready to track your websites.

Requirements

  • A server with Ubuntu 26.04 LTS (or 24.04 LTS) and a user with sudo rights.
  • A DNS A record for stats.example.com pointing to the server, for example 203.0.113.10.
  • Ports 80 and 443 open in your firewall.

Matomo needs a web server, PHP and MySQL or MariaDB. Its documentation recommends the latest PHP 8.x release, MySQL 8+ or MariaDB, and the PHP extensions curl, gd, cli, mysql, xml and mbstring.

Step 1: Install Apache, MariaDB and PHP

sudo apt update
sudo apt install apache2 mariadb-server php libapache2-mod-php php-cli php-mysql php-curl php-gd php-xml php-mbstring unzip wget

The unversioned php packages install the release's default PHP: 8.5 on Ubuntu 26.04 and 8.3 on Ubuntu 24.04. Nothing else in this guide depends on the PHP version.

Step 2: Create the database

Open the MariaDB shell as root:

sudo mariadb

Create a database and a user with the privileges Matomo lists as required. Replace the password with your own:

CREATE DATABASE matomo;
CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'change-this-password';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON matomo.* TO 'matomo'@'localhost';
EXIT;

Matomo can archive reports faster with LOAD DATA INFILE, which needs the global FILE privilege (GRANT FILE ON *.* TO 'matomo'@'localhost';). It is optional; leave it out unless you need it.

Step 3: Download Matomo

Download the latest release and unpack it into /var/www. The archive contains a matomo directory:

cd /tmp
wget https://builds.matomo.org/matomo.zip
sudo unzip -q matomo.zip -d /var/www/
sudo rm -f "/var/www/How to install Matomo.html"

Matomo publishes a GPG signature next to each build (matomo.zip.asc); verify it as described in the Matomo installation guide before using the archive on a production server.

Give the web server user ownership of the files:

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

Step 4: Configure Apache

Create a virtual host:

sudo nano /etc/apache2/sites-available/matomo.conf
<VirtualHost *:80>
    ServerName stats.example.com
    DocumentRoot /var/www/matomo

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

    ErrorLog ${APACHE_LOG_DIR}/matomo_error.log
    CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined
</VirtualHost>

AllowOverride All matters: Matomo ships .htaccess files that block web access to config/, tmp/ and other internal directories. Enable the site and reload Apache:

sudo a2ensite matomo.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Analytics data and your login must travel over HTTPS. Obtain a certificate with Certbot's Apache plugin:

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d stats.example.com

Choose the redirect option when Certbot asks, so that HTTP requests are sent to HTTPS.

Step 5: Run the web installer

Open https://stats.example.com in a browser. The installer walks through these screens:

  1. Welcome – click Next.
  2. System Check – every item should be green. A missing PHP extension is fixed by installing the matching php- package and running sudo systemctl restart apache2.
  3. Database Setup – server 127.0.0.1, login matomo, the password from Step 2, database name matomo. Keep the default table prefix.
  4. Superuser – the administrator account you will log in with.
  5. Set up a Website – name, URL and time zone of the first site to track.
  6. JavaScript Tracking Code – copy the snippet and paste it into every page you want measured, just before the closing </head> tag.
  7. Congratulations – continue to the login page.

After logging in, visit your site once and check that the visit shows up under Visitors → Real-time.

Step 6: Schedule report archiving

By default Matomo builds reports when someone opens the dashboard, which becomes slow as traffic grows. Matomo recommends a cron job for sites with more than a few hundred visits a day. Create a log file the web server user can write to, then the cron file:

sudo touch /var/log/matomo-archive.log
sudo chown www-data:www-data /var/log/matomo-archive.log
sudo nano /etc/cron.d/matomo-archive
MAILTO="root"
5 * * * * www-data /usr/bin/php /var/www/matomo/console core:archive --url=https://stats.example.com/ > /var/log/matomo-archive.log

The job runs at five minutes past every hour as www-data, the same user as the web server. Test it once by hand:

sudo -u www-data /usr/bin/php /var/www/matomo/console core:archive --url=https://stats.example.com/

When it finishes without errors, go to Administration → System → General settings and set Archive reports when viewed from the browser to No. To enforce this for API requests as well, add the following under [General] in /var/www/matomo/config/config.ini.php:

browser_archiving_disabled_enforce = 1

Step 7: Harden and maintain

  • Force HTTPS inside Matomo by adding force_ssl = 1 under [General] in config/config.ini.php.
  • Matomo only strictly needs write access to tmp/. Keeping the whole tree owned by www-data, as above, is what allows one-click updates and Marketplace plugin installs from the interface. If you tighten ownership, also set enable_auto_update = 0 under [General] and update manually.
  • Updates appear as a notice in the dashboard. After replacing the files (or using the one-click updater), finish large database upgrades from the shell: sudo -u www-data php /var/www/matomo/console core:update.
  • Back up the matomo database and config/config.ini.php; everything else can be re-downloaded.

Matomo's own documentation covers the remaining options: Installing Matomo and How to configure Matomo for security.

Frequently asked questions

Is Piwik still available under the old name?

No. The software, website and downloads have all been called Matomo since 2018, and builds.matomo.org is the download location. For compatibility with tracking code installed years ago, Matomo still ships piwik.php and piwik.js next to matomo.php and matomo.js.

Can I use Nginx instead of Apache?

Yes. Matomo supports Nginx with PHP-FPM and maintains a reference configuration in its matomo-nginx repository. Because Nginx ignores .htaccess files, that configuration is what blocks access to config/ and tmp/, so use it rather than a generic PHP server block.

What does Matomo 6 change?

Matomo 6 was at release-candidate stage in late 2026. Its stated requirements are PHP 8.1 or newer and MySQL 8.0 or MariaDB 10.6 or newer, all of which the Ubuntu 26.04 and 24.04 packages used here satisfy, so this setup can be upgraded in place once 6.0 is released as stable.

How much server does Matomo need?

For a few small sites, a VPS with 1–2 GB of RAM running the web server and database together is enough. Database size grows with the number of tracked actions, so watch disk usage and configure log deletion under Administration → Privacy → Anonymize data if you do not need raw visit logs indefinitely.

Share story:

Continue reading other guides on How VPS.