Matomo - Google Analytics Docker Alternative
Follow these steps to set up Matomo, a simple and private alternative to Google Analytics, using Docker.
Docker Compose
Create a folder named “matomo”:
mkdir matomo
cd matomo
Create docker-compose.yml:
nano docker-compose.yml
Edit docker-compose.yml:
version: "3"
services:
db:
image: mariadb:10.11
command: --max-allowed-packet=64MB
restart: always
volumes:
- db:/var/lib/mysql:Z
environment:
- MYSQL_ROOT_PASSWORD=<password>
- MARIADB_AUTO_UPGRADE=1
- MARIADB_DISABLE_UPGRADE_BACKUP=1
env_file:
- ./db.env
app:
image: matomo
restart: always
volumes:
# - ./config:/var/www/html/config:z
# - ./logs:/var/www/html/logs:z
- matomo:/var/www/html:z
environment:
- MATOMO_DATABASE_HOST=db
env_file:
- ./db.env
ports:
- 10093:80
volumes:
db:
matomo:
Replace <password>
with your password. If your password has a $
symbol, write $$
instead. This is because Docker thinks $
is a variable name and $$
tells it to use a normal $
.
(Retrieved from Matomo GitHub on January 22, 2025)
Create db.env:
nano db.env
Edit db.env:
MYSQL_PASSWORD=<password>
MYSQL_DATABASE=matomo
MYSQL_USER=matomo
MATOMO_DATABASE_ADAPTER=mysql
MATOMO_DATABASE_TABLES_PREFIX=matomo_
MATOMO_DATABASE_USERNAME=matomo
MATOMO_DATABASE_PASSWORD=<db_password>
MATOMO_DATABASE_DBNAME=matomo
MARIADB_AUTO_UPGRADE=1
MARIADB_INITDB_SKIP_TZINFO=1
Use the same password you set in docker-compose.yml for MYSQL_PASSWORD
, and create new password for MATOMO_DATABASE_PASSWORD
. Write $$
as $
(the reverse of what you did in the docker-compose.yml file).
Caddy
Install Caddy:
apt install caddy
sudo systemctl enable caddy
Open Caddyfile:
nano /etc/caddy/Caddyfile
Edit Caddyfile:
example.com {
# You can use a different name instead of "/radar," like "/analytics" or "/traffic."
route /radar* {
uri strip_prefix /radar
redir https://radar.{host}{uri}
}
}
# To use a different port, change the "ports:" section in your docker-compose.yml file.
radar.example.com {
reverse_proxy localhost:10093
encode zstd gzip
}
Restart Caddy:
sudo systemctl restart caddy
Go to Matomo at https://radar.example.com or at https://example.com/radar if you prefer using a subpath.