Setup Kimai with Caddy and MariaDB on Fedora 37

Kimai is a time-tracking software designed for businesses and freelancers to monitor and manage their working hours efficiently. It offers features such as time recording, project tracking, invoicing, and reporting, providing users with detailed insights into their productivity and project timelines.

Wording in this tutorial

string

meaning

foo.net

domain

xxxxxxxxx

any string

xx.xx.xxx.xx

IPv4 address

xxxx:xxx:xxxx:xxxx::1

IPv6 address

Install packages

sudo dnf install \
   caddy \
   composer \
   mariadb-server mariadb php-mysqlnd \
   php php-gd php-pecl-zip php-pgsql php-cli

# Start
sudo systemctl start mariadb
sudo systemctl start php-fpm

# Start automatically at boot
sudo systemctl enable mariadb
sudo systemctl enable php-fpm

Configure MariaDB

Create user and database.

sudo mysql -u root
CREATE DATABASE kimai;
CREATE USER caddy@localhost IDENTIFIED BY 'THE_PASSWORD';
GRANT ALL PRIVILEGES ON kimai.* TO caddy@localhost;
FLUSH PRIVILEGES;

# Test priviledges:
SHOW GRANTS FOR caddy@localhost;

EXIT

sudo -u caddy vi /var/www/kimai/.env:

DATABASE_URL=mysql://caddy:THE_PASSWORD@127.0.0.1:3306/kimai?charset=utf8&serverVersion=mariadb-10.5.8

Configure PHP

sudo vi /etc/php.ini:

# Change:
upload_max_filesize = 200M

# Add:
post_max_size = 200M
sudo systemctl restart php-fpm.service

Prepare Kimai

cd /var/www/
sudo git clone -b 1.30.10 --depth 1 https://github.com/kimai/kimai.git
sudo chown -R caddy:caddy /var/www/kimai/
cd kimai/
sudo -u caddy composer install --optimize-autoloader -n
sudo -u caddy bin/console kimai:install -n

Configure Caddy

sudo mkdir /var/log/caddy
sudo chown caddy /var/log/caddy
sudo chgrp caddy /var/log/caddy

sudo nvim /etc/caddy/Caddyfile.d/foo.net.caddyfile

foo.net {
    root * /var/www/kimai/public
    php_fastcgi unix//run/php-fpm/www.sock
    file_server
    encode gzip
    # rewrite * /index.php?q={path}&{query}

    log {
        output file /var/log/caddy/foo.net-access.log
    }

    @static {
        file
        path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.pdf *.webp
    }
    header @static Cache-Control max-age=5184000
}

Configure PHP

# Replace
sudo sed -i 's/^user = apache$/user = caddy/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/^group = apache$/group = caddy/g' /etc/php-fpm.d/www.conf
# Append
sudo sed -i 's/\blisten.acl_users =.*\b/&,caddy/' /etc/php-fpm.d/www.conf

sudo systemctl restart caddy

Configure Kimai

Create first user:

sudo -u caddy bin/console kimai:user:create suadmin admin@foo.net ROLE_SUPER_ADMIN

Some Kimai settings

  • Customers

  • Projects

  • Activities

    • assign to a project if related

    • define hourly rate

  • Time rounding

    E.g., rounding of the duration in minutes: 15

  • Settings -> Invoice number format