This guide provides a full Ansible playbook to deploy Matomo with Docker Compose on Debian 10+, Ubuntu LTS, and RHEL 9+ compatible hosts. The latest version is Matomo 5.7.1 (released February 3, 2026).
- name: Deploy Matomo
hosts: matomo
become: true
vars:
app_root: /opt/matomo
app_port: 8080
matomo_version: "5.7.1" # Latest stable version
matomo_db_user: "matomo"
matomo_db_name: "matomo"
matomo_db_password: "change_me_to_strong_password"
mysql_root_password: "change_me_to_strong_root_password"
tasks:
- name: Install Docker on Debian/Ubuntu
apt:
name:
- docker.io
- docker-compose-plugin
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Docker on RHEL family
dnf:
name:
- docker
- docker-compose-plugin
state: present
when: ansible_os_family == "RedHat"
- name: Add ansible user to docker group
user:
name: "{{ ansible_user }}"
groups: docker
append: yes
when: ansible_user is defined
- name: Enable and start Docker
service:
name: docker
state: started
enabled: true
- name: Create application directory
file:
path: "{{ app_root }}"
state: directory
mode: "0755"
- name: Write Docker Compose file
template:
src: docker-compose.yml.j2
dest: "{{ app_root }}/docker-compose.yml"
mode: "0644"
- name: Start application stack
command: docker compose up -d
args:
chdir: "{{ app_root }}"
register: docker_up_result
- name: Wait for Matomo to be ready
uri:
url: "http://localhost:{{ app_port }}"
method: GET
status_code: 200
retries: 30
delay: 10
when: docker_up_result is succeeded
- name: Configure firewall (ufw)
ufw:
rule: allow
port: "{{ app_port }}"
proto: tcp
when: ansible_pkg_mgr in ["apt", "aptitude"]
Create this template file at templates/docker-compose.yml.j2:
version: '3.8'
services:
matomo:
image: matomo:{{ matomo_version }}-apache
restart: unless-stopped
ports:
- "{{ app_port }}:80"
environment:
- MATOMO_DATABASE_HOST=db
- MATOMO_DATABASE_ADAPTER=mysql
- MATOMO_DATABASE_TABLES_PREFIX=matomo_
- MATOMO_DATABASE_USERNAME={{ matomo_db_user }}
- MATOMO_DATABASE_PASSWORD={{ matomo_db_password }}
- MATOMO_DATABASE_DBNAME={{ matomo_db_name }}
- PHP_MEMORY_LIMIT=512M
volumes:
- matomo_data:/var/www/html
depends_on:
- db
networks:
- matomo-network
db:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: {{ mysql_root_password }}
MYSQL_DATABASE: {{ matomo_db_name }}
MYSQL_USER: {{ matomo_db_user }}
MYSQL_PASSWORD: {{ matomo_db_password }}
volumes:
- matomo_db:/var/lib/mysql
networks:
- matomo-network
volumes:
matomo_data:
matomo_db:
networks:
matomo-network:
driver: bridge
After the initial deployment, you’ll need to:
http://your-server-ip:8080# Add to crontab
5 * * * * www-data /usr/bin/php /var/www/html/matomo/console core:archive --url=http://your-server-ip:8080 > /var/log/matomo-archive.log
config/config.ini.php:[General]
browser_archiving_disabled_enforce = 1
You can also define variables in your inventory or group_vars:
# group_vars/matomo.yml
matomo_version: "5.7.1"
matomo_url: "https://matomo.yourdomain.com"
matomo_admin_email: "admin@yourdomain.com"
matomo_timezone: "UTC"
Then reference these in your playbook and templates.
Any questions?
Feel free to contact us. Find all contact information on our contact page.