How to Install Matomo on Your Synology NAS

How to Install Matomo on Your Synology NAS

Matomo 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. It’s very similar to Google Analytics, but you can host it on your Synology NAS. In this step by step guide I will show you how to install Matomo on your Synology NAS using Docker & Portainer. Note: You can also use Umami or Plausible on your Synology NAS as alternative to Matomo.

💡Note: This guide works perfectly with the latest version of Matomo 5.1.2

  • STEP 1

Please Support My work by Making a Donation.

  • STEP 2

Install Portainer using my step by step guide. If you already have Portainer installed on your Synology NAS, skip this STEP. Attention: Make sure you have installed the latest Portainer version.

  • STEP 3

Make sure you have a synology.me Wildcard Certificate. Follow my guide to get a Wildcard Certificate. If you already have a synology.me Wildcard certificate, skip this STEP.

  • STEP 4

Go to Control Panel / Login Portal / Advanced Tab / click Reverse Proxy. Follow the instructions in the image below.

Matomo Synology NAS Set up 11

  • STEP 5

Now click the “Create” button. Follow the instructions in the image below.

Matomo Synology NAS Set up 12

  • STEP 6

After you click the Create button, the window below will open. Follow the instructions in the image below.

On the General area, set the Reverse Proxy Name description: type in matomo. After that, add the following instructions:

Source:
Protocol: HTTPS
Hostname: matomo.yourname.synology.me
Port: 443

Check Enable HSTS

Destination:
Protocol: HTTP
Hostname: localhost
Port: 8597

Matomo Synology NAS Set up 13 new

  • STEP 7

On the Reverse Proxy Rules click the Custom Header tab. Click Create and then, from the drop-down menu, click WebSocket. After you click on WebSocket, two Header Names and two Values will be automatically added. Click Save. Follow the instructions in the image below.

Synology Proxy WebSocket

  • STEP 8

Go to Control Panel / Network / Connectivity tab/ Check Enable HTTP/2 then click Apply. Follow the instructions in the image below.

Matomo Synology NAS HTTP2

  • STEP 9

Go to Control Panel / Security / Advanced tab/ Check Enable HTTP Compression then click Apply. Follow the instructions in the image below.

Matomo Synology NAS HTTP Compression

  • STEP 10

Go to File Station and open the docker folder. Inside the docker folder, create one new folders and them matomo. Follow the instructions in the image below.
Note: Be careful to enter only lowercase, not uppercase letters.

1 Matomo Synology NAS Set up new 2025

  • STEP 11

Now create two new folders inside the matomo folder that you have previously created at STEP 10 and name them data and db. Follow the instructions in the image below.
Note: Be careful to enter only lowercase, not uppercase letters.

2 Matomo Synology NAS Set up new 2025

  • STEP 12

Right click on the matomo folder that you have previously created at STEP 10, then click Properties. Follow the instructions in the image below.

3 Matomo Synology NAS Set up new 2025

  • STEP 13

Go to the Permission tab then click Advanced options. From the drop-down menu choose “Make inherited permissions explicit“. Follow the instructions in the image below.

4 Matomo Synology NAS Set up new 2025

  • STEP 14

Select Everyone then click the Edit tab. Follow the instructions in the image below.

5 Matomo Synology NAS Set up new 2025

  • STEP 15

Check all Read and Write Permissions. Click Done. Follow the instructions in the image below.

6 Matomo Synology NAS Set up new 2025

  • STEP 16

After you click Done on STEP 15, check “Apply to this folder, sub-folders and files“. Click Save. Follow the instructions in the image below.

7 Matomo Synology NAS Set up new 2025

  • STEP 17

Log into Portainer using your username and password. On the left sidebar in Portainer, click on Stacks then + Add stack. Follow the instructions in the image below.

1 Synology Portainer Add Stack

  • STEP 18

In the Name field type in matomo. Follow the instructions in the image below.

Note: Copy Paste the code below in the Portainer Stacks Web editor.

services:
  db:
    container_name: Matomo-DB
    hostname: matomo-db
    image: mariadb:11.4-noble #LTS Long Time Support Until May 29, 2029.
    command: --max_allowed_packet=1073741824
    restart: on-failure:5
    volumes:
      - /volume1/docker/matomo/db:/var/lib/mysql:rw
    environment:
      MARIADB_ROOT_PASSWORD: matomopass
      MARIADB_DATABASE: matomodb
      MARIADB_USER: matomouser
      MARIADB_PASSWORD: matomopass
      TZ: Europe/Bucharest
      
  matomo:
    container_name: Matomo
    image: matomo:latest
    healthcheck:
      test: timeout 10s bash -c ':> /dev/tcp/127.0.0.1/80' || exit 1
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 90s
    environment:
       PUID: 1026
       PGID: 100
       TZ: Europe/Bucharest
       MATOMO_DATABASE_HOST: matomo-db
       MATOMO_DATABASE_USERNAME: matomouser
       MATOMO_DATABASE_PASSWORD: matomopass
       MATOMO_DATABASE_DBNAME: matomodb
    ports:
      - 8597:80
    depends_on:
      - db
    volumes:
      - /volume1/docker/matomo/data:/var/www/html:rw
    restart: on-failure:5

Note: After you paste the code in the Web editor, change the value for TZ. (Select your current Time Zone from this list.)
Note: After you paste the code in the Web editor, change the value numbers for PUID and PGID with your own values. (Follow my step by step guide on how to do this.)

8 Matomo Synology NAS Set up new 2025

  • STEP 19

Scroll down on the page until you see a button called Deploy the stack. Click on it. Follow the instructions in the image below. The installation process can take up to a few minutes. It will depend on your Internet speed connection.

9 Matomo Synology NAS Set up new 2025

  • STEP 20

If everything goes right, you will see this message at the top right of your screen: “Success Stack successfully deployed“.

10 Matomo Synology NAS Set up new 2025

  • STEP 21

Go back to STEP 1 or you will deal with karma 🙂

  • STEP 22

Now open your browser and type in your HTTPS/SSL certificate like this https://matomo.yourname.synology.me In my case it’s https://matomo.mariushosting.synology.me If everything goes right, you will see the Matomo installation page. Click NEXT. Follow the instructions in the image below.

11 Matomo Synology NAS Set up new 2025

  • STEP 23

Click NEXT. Follow the instructions in the image below.

12 Matomo Synology NAS Set up new 2025

  • STEP 24

Click NEXT. Follow the instructions in the image below.

13 Matomo Synology NAS Set up new 2025

  • STEP 25

Click NEXT. Follow the instructions in the image below.

14 Matomo Synology NAS Set up new 2025

  • STEP 26

Go back to STEP 1 or you will deal with karma 🙂

  • STEP 27

Add a Username, a Password and your Email address for your matomo instance. Click NEXT. Follow the instructions in the image below.

15 Matomo Synology NAS Set up new 2025

  • STEP 28

  1. Add your Website name
  2. Add your Website URL
  3. Select your Website time zone

Click NEXT. Follow the instructions in the image below.

16 Matomo Synology NAS Set up new 2025

  • STEP 29

Copy your own JavaScript Tracking Code to a .txt file (you will need it later). Follow the instructions in the image below.

17 Matomo Synology NAS Set up new 2025

  • STEP 30

Scroll down on the page until you see the NEXT button. Click on it. Follow the instructions in the image below.

18 Matomo Synology NAS Set up new 2025

  • STEP 31

Click CONTINUE TO MATOMO. Follow the instructions in the image below.

19 Matomo Synology NAS Set up new 2025

  • STEP 32

Add the Username and Password you have previously created at STEP 27. Click SIGN IN. Follow the instructions in the image below.

20 Matomo Synology NAS Set up new 2025

  • STEP 33

Your Matomo instance at a glance!

21 Matomo Synology NAS Set up new 2025

  • STEP 34

Paste your personal Matomo JavaScript Tracking code that you have automatically generated at STEP 29 on your website between the <​head> and </head> tags of your site, then update your file. For example, I have a WordPress website hosted on a Synology NAS. If you have a WordPress website hosted elsewhere, know that the process is the same. Log into your WordPress admin Dashboard. On the left sidebar, click on “Theme Editor or Theme File Editor”. Select your theme, then search for the header.php file. Paste your personal Matomo JavaScript Tracking code that you have automatically generated at STEP 29 in the header.php file between the <​head> and </head> tags of your site, then update your file. Follow the instructions in the image below.
Note: Paste the code in the website you have chosen at STEP 28. You can add multiple websites via the Matomo Dashboard later.

Matomo Synology NAS Set up 28

  • STEP 35

After the JavaScript code is added to your website, Matomo will start to collect Real-Time analytics of your website. My blog doesn’t have any TRACKING CODE on it. I just installed Matomo to show you how it works and how easily you can implement it on your website. I have already uninstalled it. Don’t forget to go back to STEP 1. I have worked hard for this guide so you can enjoy it.

23 Matomo Synology NAS Set up new 2025

  • STEP 36

Install Text Editor via Synology “Package Center”. (Mandatory STEP.) If you already have Text Editor installed on your Synology NAS, skip this STEP.

Synology Install Text Editor 2023

  • STEP 38

Navigate under File Station in docker / matomo / data / config

Identify the config.ini.php file, then open it.
Under [database] add the following line: schema = Mariadb
Under [General] add the following line: force_ssl = 1

Click X to save the file. Follow the instructions in the image below.

22 Matomo Synology NAS Set up new 2025

  • STEP 39

Set Up Email Notifications on Matomo.

Enjoy Matomo!

🆘TROUBLESHOOTING

If you encounter issues by using this container, make sure to check out the Common Docker issues article.

Note: Can I run Docker on my Synology NAS? See the supported models.
Note: How to Back Up Docker Containers on your Synology NAS.
Note: Find out how to update the Matomo container with the latest image.
Note: How to Free Disk Space on Your NAS if You Run Docker.
Note: Instead of the synology.me DDNS you can also use your own domain name.
Note: How to Schedule Start & Stop For Docker Containers.
Note: How to Activate Email Notifications.
Note: How to Add Access Control Profile on Your NAS.
Note: How to Change Docker Containers Restart Policy.
Note: How to Use Docker Containers With VPN.
Note: Convert Docker Run Into Docker Compose.
Note: How to Clean Docker.
Note: How to Clean Docker Automatically.
Note: Best Practices When Using Docker and DDNS.
Note: Some Docker Containers Need WebSocket.
Note: Find out the Best NAS Models For Docker.
Note: Activate Gmail SMTP For Docker Containers.

This post was updated on Tuesday / October 1st, 2024 at 12:02 AM