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.

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

  • STEP 1

Please Support My work by Making a Donation.

  • STEP 2

Install Docker via Synology “Package Center”.

Install Docker Synology DSM 7

  • STEP 3

Install Portainer using my step by step guide. If you already have Portainer installed on your Synology NAS, skip this STEP.

  • STEP 4

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

Matomo Synology NAS Set up 1

  • STEP 5

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.

Matomo Synology NAS Set up 2

  • STEP 6

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.

version: '2.9'

services:
  
  mariadb:
    container_name: mariadb
    image: mariadb
    command: --max_allowed_packet=1073741824
    restart: always
    volumes:
      - mariadb:/var/lib/mysql
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_DATABASE=matomodb
  matomo:
    container_name: matomo
    environment:
      - PUID=1026
      - PGID=100
      - TZ=Europe/Bucharest
    ports:
      - 8597:80
    links:
      - mariadb
    volumes:
      - /volume1/docker/matomo:/var/www/html
    image: matomo
    restart: always

volumes:
  mariadb: # matomo

Matomo Synology NAS Set up 3

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.)
Note: After you paste the code in the Web editor, change the value for TZ. (Select your current Time Zone from this list.)

  • STEP 7

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.

Matomo Synology NAS Set up 4

  • STEP 8

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

Matomo Synology NAS Set up 5

  • STEP 9

Follow my step by step guide on how to activate your synology.me DDNS on DSM 7
Follow my step by step guide on how to activate your synology.me DDNS on DSM 6.2.4
Note: If you already own a synology.me DDNS, skip this STEP.

  • STEP 10

Go to Control Panel / Security / Certificate then click the Add tab. Follow the instructions in the image below.

Matomo Synology NAS Set up 6

  • STEP 11

After you click the Add tab on STEP 10 a new pop up window will open. Select Add a new certificate then click Next. Follow the instructions in the image below.

Matomo Synology NAS Set up 7

  • STEP 12

After you click Next, select a Description for your certificate. I chose “matomo” because I will be using this certificate for my matomo container. Select Get a certificate from Let’s Encrypt then click Next. Follow the instructions in the image below.

Matomo Synology NAS Set up 8

  • STEP 13

After you click Next, on the Domain name area, type in matomo.yourname.synology.me Type in your email address in the Email area, then click Done. Follow the instructions in the image below.

Matomo Synology NAS Set up 9

  • STEP 14

After you click Done, you will have to wait a few seconds for your new certificate to be created. If everything goes right, you will see your new certificate in the Certificate area.

Matomo Synology NAS Set up 10

Note: If you fail to create a new certificate, try to create a new certificate using your http://yournasip:5000 instead using the https connection.

  • STEP 15

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 16

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

Matomo Synology NAS Set up 12

  • STEP 17

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 or the Description you have already chosen at STEP 12. After that, add the following instructions:

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

Destination:
Protocol: HTTP
Hostname: localhost
Port: 8597

Matomo Synology NAS Set up 13

  • STEP 18

Go to Control Panel / Security / Certificate / Select the certificate you have previously created at STEP 14, then click on Settings. Follow the instructions in the image below.

Matomo Synology NAS Set up 14

  • STEP 19

Your new certificate should be mirroring. Select your Certificate and, from the dropdown menu, select your Certificate again, then click OK. Follow the instructions in the image below.

Matomo Synology NAS Set up 15

  • STEP 20

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

  • STEP 21

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.

Matomo Synology NAS Set up 16

  • STEP 22

Click NEXT. Follow the instructions in the image below.

Matomo Synology NAS Set up 17

  • STEP 23

  1. Database Server: type in mariadb
  2. Login: type in root
  3. Password: leave blank
  4. Database Name: type in matomodb

Click NEXT. Follow the instructions in the image below.

Matomo Synology NAS Set up 18

  • STEP 24

Click NEXT. Follow the instructions in the image below.

Matomo Synology NAS Set up 19

  • STEP 25

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

  • STEP 26

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

Matomo Synology NAS Set up 20

  • STEP 27

  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.

Matomo Synology NAS Set up 21

  • STEP 28

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

Matomo Synology NAS Set up 22

  • STEP 29

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

Matomo Synology NAS Set up 23

  • STEP 30

Congratulations! Your Matomo installation is complete.

Matomo Synology NAS Set up 24

  • STEP 31

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

Matomo Synology NAS Set up 25

  • STEP 32

Sign in. Add the Username and Password you have previously created at STEP 26. Follow the instructions in the image below.

Matomo Synology NAS Set up 26

  • STEP 33

Welcome to your Matomo Analytics administrator dashboard!

Matomo Synology NAS Set up 27

  • STEP 34

Paste your personal Matomo JavaScript Tracking code you have automatically generated at STEP 28 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, click on the left sidebar on “Theme Editor”, select your theme then search for the header.php file. Paste your personal Matomo JavaScript Tracking code you have automatically generated at STEP 28 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 27. 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.

Matomo Synology NAS Set up 29

  • STEP 36

Don’t forget to Enable HTTP/2

Note: Can I run Docker on my Synology NAS? See the supported models.
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.

This post was updated on Thursday / October 21st, 2021 at 8:26 PM