Skip to content
Serverküche
Search

Loading search …

Applications Difficulty: Advanced

Kimai: Time Tracking for Freelancers & Small Teams

Kimai 2.72 with MariaDB behind Traefik: customer, project, activity – and the health check that hides the container without the right TRUSTED_HOSTS line.

· 12 min read ·Duration: approx. 40 minutes
Table of contents

Anyone who bills by the hour writes those hours down somewhere in the end: in a spreadsheet, in a SaaS account, or from memory straight into the invoice. Kimai is the third option: a full-grown time tracker on your own server, where your clients’ data stays where you are accountable for it.

What are we building?

We run Kimai 2.72.0 with MariaDB 11.8.9 behind Traefik. At the end you create customers, projects and activities, record time with a stopwatch or by hand, store an hourly rate and pull a weekly report plus a CSV or Excel export out of it, the basis for any invoice.

Kimai is not a weekend project: it knows teams, roles, budgets, rates, working contracts, invoice templates and a REST API. This tutorial builds the core that all of it sits on.

One line decides whether the site appears at all

The Kimai image ships its own Docker health check that calls itself over http://127.0.0.1:8001. If TRUSTED_HOSTS contains only your domain, Kimai rejects that request. The container then stays unhealthy forever, and Traefik silently skips it. The result: no certificate, no reachable site, and no error you would see without a debug log.

That is why TRUSTED_HOSTS below carries |localhost|127.0.0.1. Do not drop it.

Requirements

🍳 Recommendation Ad

VPS 1000 G12.5

4 vCores · 8 GB RAM · 128 GB SSD

from €14.50/month

Measured: Kimai about 140 MB, MariaDB about 150 MB. It runs next to other services on the small VPS.

Go to netcup →

💶 1 month free:

Single use, valid for VPS 1000 G12.5. Redeem in the cart →

💶 €5.95 voucher for new netcup customers: always valid · not for domains or VPS Lite

All netcup vouchers →

About the screenshots

The screenshots show the interface set to German. The menu structure is identical in English, and the English labels are named in the text.

Step by step

Step 1: Generate the credentials

Kimai needs four secrets. Create them before you write the configuration:

Terminal
mkdir -p /opt/kimai && cd /opt/kimai
openssl rand -hex 32      # APP_SECRET
openssl rand -hex 16      # database password
openssl rand -hex 16      # database root password

The fourth is the starting password for the administrator. Use a long one you will replace right away:

Terminal
openssl rand -base64 18

APP_SECRET signs sessions and form tokens. Swap it and every login becomes invalid, so it belongs in your backup. The database root password is only needed by the container itself; Kimai connects with the regular user.

Step 2: The configuration

INI
# /opt/kimai/.env
DOMAIN=time.YOUR_DOMAIN
APP_SECRET=YOUR_APP_SECRET
DB_PASSWORD=YOUR_DB_PASSWORD
DB_ROOT_PASSWORD=YOUR_ROOT_PASSWORD
ADMIN_MAIL=you@YOUR_DOMAIN
ADMIN_PASSWORD=YOUR_STARTING_PASSWORD
Terminal
chmod 600 /opt/kimai/.env

Step 3: The stack

YAML
# /opt/kimai/compose.yaml
services:
  db:
    image: mariadb:11.8.9
    container_name: kimai-db
    restart: unless-stopped
    command: --default-storage-engine innodb
    environment:
      MARIADB_DATABASE: kimai
      MARIADB_USER: kimai
      MARIADB_PASSWORD: ${DB_PASSWORD}
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    volumes:
      - dbdata:/var/lib/mysql
    networks: [kimai-intern]
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 30s

  app:
    image: kimai/kimai2:2.72.0
    container_name: kimai
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      APP_SECRET: ${APP_SECRET}
      TRUSTED_HOSTS: ${DOMAIN}|localhost|127.0.0.1
      TRUSTED_PROXIES: 172.16.0.0/12
      ADMINMAIL: ${ADMIN_MAIL}
      ADMINPASS: ${ADMIN_PASSWORD}
      DATABASE_URL: "mysql://kimai:${DB_PASSWORD}@db/kimai?charset=utf8mb4&serverVersion=11.8.9-MariaDB"
      TZ: Europe/Berlin
    volumes:
      - data:/opt/kimai/var/data
      - plugins:/opt/kimai/var/plugins
    networks: [kimai-intern, proxy]
    labels:
      - traefik.enable=true
      - traefik.docker.network=proxy
      - traefik.http.routers.kimai.rule=Host(`time.YOUR_DOMAIN`)
      - traefik.http.routers.kimai.entrypoints=websecure
      - traefik.http.routers.kimai.tls.certresolver=le
      - traefik.http.services.kimai.loadbalancer.server.port=8001

volumes:
  dbdata:
  data:
  plugins:

networks:
  kimai-intern:
    internal: true
  proxy:
    external: true

Four spots deserve a look. The Apache inside the Kimai container listens on port 8001, not 80; without loadbalancer.server.port=8001 Traefik talks into the void. serverVersion in DATABASE_URL tells Doctrine which SQL dialect to speak. With MariaDB the -MariaDB suffix belongs there. If the value does not match the database, Doctrine builds queries for the wrong server. TRUSTED_PROXIES is the Docker network Traefik comes from; otherwise Kimai considers the connection unencrypted. And the database sits in a network with internal: true and is therefore unreachable both from outside and from the proxy network.

Start it:

Terminal
cd /opt/kimai
docker compose up -d
docker compose ps --format '{{ .Name }}\t{{ .Status }}'
Ausgabe
kimai     Up 25 seconds (healthy)
kimai-db  Up 36 seconds (healthy)

The first start takes a moment. Kimai creates the schema, clears and warms the cache. Expect half a minute to a minute until (healthy) shows up. And that (healthy) is exactly what Traefik waits for: as long as it is missing there is neither a route nor a certificate.

Terminal
curl -s -o /dev/null -w "%{http_code}\n" https://time.YOUR_DOMAIN/
Ausgabe
302

The redirect leads to the login page, so the service is up.

Step 4: First login and the setup wizard

The username is admin, not the mail address from ADMINMAIL. That one only ends up in the profile. The password is the one from ADMIN_PASSWORD.

After signing in, Kimai walks every new user through a short wizard once. It starts in English; on the second page you can switch Language to your own. That page is the important one:

Kimai’s setup wizard with fields for language, time/date/currency format, timezone and design
Language, format and timezone. The timezone is the one that matters.

Change the timezone. Kimai defaults it to UTC, even with TZ=Europe/Berlin set in the container: the environment variable applies to PHP, while the timezone in the profile belongs to the user. For a time tracker that means a two-hour offset in every entry.

These settings are per user. Every new team member runs the same wizard and picks their own.

Change the starting password, then delete the lines

Switch to a password of your own now under My profile → Password. After that you can remove ADMINMAIL and ADMINPASS from compose.yaml: the two variables only create the user if it is missing. A changed password stays valid after restarting the container, and without the lines logging in keeps working unchanged. As long as they stay, a valid login password sits in plain text in your configuration.

Step 5: Customer, project, activity

Kimai assigns every recorded minute to three things, and they hang together:

Ausgabe
Customer    who pays         -> Sample Customer Ltd
Project     what for         -> Website relaunch
Activity    what exactly     -> Development, Meeting, Testing

No customer, no project; no project, no time entry. First create the customer under Administration → Customers → Create; the name is the only required field.

Then the project under Administration → Projects:

Kimai’s “create project” form with name, customer, project number and an hourly quota of 40:00
The project hangs off the customer. Hourly quota and budget are optional but useful.

The hourly quota (40:00 here) is the number Kimai measures progress against. The project page then shows a line like Working hours – 55.00% 22:00 / 40:00. That is the most honest early warning against fixed-price projects going sideways.

Activities (Administration → Activities) come in two flavours: bound to a project, or global. Global means you can use them in every project, exactly right for classics like “Development” or “Meeting”. The Allow global activities switch on the project decides whether they show up there.

Step 6: Record time

Two routes lead to the same entry. The stopwatch is the start button at the top right, next to your name. The running time is visible there afterwards, and a second click ends the entry. By hand you go through My times → Create, with date, start and end. Leave the end empty and you get a running entry, which is handy when you forgot to hit start.

Kimai’s “my times” list with nine entries, one of them without an end time as a running record
The top entry is still running: end shows \"-\", and the clock ticks in the top right

A running entry does not show up in the reports yet. It is only counted once it has been stopped. Anyone wondering why today reads 0:00 in the report usually still has the clock going.

Step 7: Store an hourly rate

Without an hourly rate every currency column stays empty. You set the rate on the project (Project → Prices), either per user or for everyone:

Ausgabe
Price           85          price per hour
Internal price  (empty)     falls back to the normal price
Fixed price     off         otherwise every entry costs the same

The hourly rate is not retroactive

Kimai freezes the price when an entry is saved. A rate stored later does not change times already recorded: seven entries created before the rate stay at €0.00, while a new three-hour entry immediately shows up as €255.00 in the project overview. So if you take Kimai into production, set the rates before the first recorded hour or fix the old entries one by one.

Step 8: Report and export

Reporting holds a dozen views; the everyday one is Weekly view for one user:

Kimai’s weekly report with times per customer, project and activity for week 43
Customer, project and activity per weekday, with a total across everything

For the invoice you use Time Tracking → Export. Filter period, customer and project there, click Search and get a preview with duration and amount:

Kimai’s export page with filters, a preview over 25:00 hours and the CSV, Excel, PDF and print buttons
Filter and search first, then export. The total is already in the header.

Four outputs are available: CSV, Excel, PDF and Print. CSV and Excel arrive as files with the date in the name (20261026-kimai-export.csv and .xlsx); the PDF button opens a menu of templates. One quirk of the CSV: the column headings are English (Date,From,To,Duration,Currency,Price,…) regardless of the interface language.

The Mark as exported switch ticks a flag on the entries you just exported. Afterwards you can hide them with the Exported = No filter, so next month you do not accidentally export the same hours twice.

Step 9: More users

Under System → Users → Create you add colleagues. Besides name, mail and password you pick language, timezone and optionally a role:

Ausgabe
(none)           User – records and sees only their own times
ROLE_TEAMLEAD    Team lead – manages their own teams
ROLE_ADMIN       Administrator – customers, projects, users
ROLE_SUPER_ADMIN System admin – plus the system settings

Without a role a user is simply a user, and that is the right default: such an account sees nothing but its own timesheet, Administration and System are missing from the menu, and calling /en/admin/user/ directly ends in a 403 error page.

If you want finer control over who sees which projects, use teams: a team gets members and is attached to customers or projects. As long as no team is assigned, a project is visible to everyone, and the project page says so too.

For accounts with administrator rights, My profile → Two-Factor (2FA) is worth the two minutes; Kimai brings TOTP along out of the box.

When it doesn’t work

The site is unreachable and the browser reports an invalid certificate. Check docker compose ps first: if it permanently reads (health: starting) or (unhealthy), that is your cause. Traefik skips containers that are not healthy. Its debug log then says Filtering unhealthy or starting container, and since no router exists, Traefik never requests a certificate either. The trigger is almost always TRUSTED_HOSTS: the built-in health check calls http://127.0.0.1:8001, and Kimai answers with a 400 if only the domain is listed. The log (docker compose logs app) shows Untrusted Host "127.0.0.1". Set TRUSTED_HOSTS: ${DOMAIN}|localhost|127.0.0.1 and rebuild with docker compose up -d --force-recreate app.

Every recorded time is off by a couple of hours. The timezone in the user profile is still UTC. It is a user setting and is not taken from TZ in the container; that variable only applies to PHP. Fix it under My profile → Preferences. Careful: entries already recorded keep their stored time and shift along in the display.

Logging in with the mail address from ADMINMAIL fails. The username is admin, the mail address only lands in the account’s profile. If you locked yourself out, create a new account inside the container: docker compose exec -T app /opt/kimai/bin/console kimai:user:create emergency emergency@YOUR_DOMAIN ROLE_SUPER_ADMIN "YOUR_PASSWORD". On success it answers [OK] Success! Created user: emergency. Pass the password as the fourth argument. Leave it out and the command asks with Please enter the password:, and because of -T your input then shows up readable in the terminal. In a script without input it aborts with The password may not be empty.

The report shows hours but 0.00 €. The hourly rate is frozen when an entry is saved and does not apply retroactively. Enter the rate on the project (or the user) and verify with a fresh test entry. If an amount appears there, the setting is right and only the old entries need fixing.

A new user sees no projects or gets a 403. That is the expected behaviour of an account without a role: own times yes, administration no. If the projects are missing from their selection instead, a team is involved. As soon as a team is assigned to a project, only its members see it. Either add the user to the team or remove the team assignment from the project.

Your problem is not listed? Search all error messages →

Maintenance & backups

Kimai releases often. From 2.58.0 (25 May 2026) to 2.72.0 (13 November 2026) there were 17 releases, one every ten days on average. If you do not want to chase that, pin the major version (kimai/kimai2:2) and update deliberately; if you pin the exact version you always know what is running. Both are defensible, latest is not.

Terminal
cd /opt/kimai
docker compose exec -T db sh -c 'mariadb-dump -uroot -p"$MARIADB_ROOT_PASSWORD" kimai' > before-update-$(date +%F).sql
sed -i 's/kimai2:2.72.0/kimai2:NEW_VERSION/' compose.yaml
docker compose pull && docker compose up -d
docker compose logs app --tail 20

The dump takes the password from the database container’s own environment, which is why the command sits in single quotes and is evaluated there, not in your shell.

The container handles schema migration and cache warming on start by itself. Every restart shows it in the log (Rebuilding your cache, Kimai config was reloaded). That is why the first request after an update is slow; after about a minute (healthy) is back.

Three things need backing up:

Ausgabe
/opt/kimai/.env         # APP_SECRET and database passwords
mariadb-dump output     # customers, projects, times, users
volume kimai_data       # uploaded files, invoice templates

A database dump without the .env is of little use: with a new APP_SECRET every session becomes invalid and logging in breaks. Both belong together in your Restic backup, because customer names, project names and hourly rates live here.

The footprint is modest and stays that way:

Ausgabe
kimai     ~140 MB RAM
kimai-db  ~150 MB RAM
volume kimai_dbdata   173 MB after setup

Those 173 MB are almost entirely the empty MariaDB scaffolding. Time entries are a few bytes each, even ten years of full-time work will not come near a gigabyte.

And the effort? An update every few weeks with a dump beforehand, ten minutes. Once a quarter a look at the user list and the team assignments. The real discipline lies elsewhere: a time tracker is only as good as the habit of actually starting the clock.

You might also like