Time Tracking: Kimai2 0.9 on OpenBSD
Tags: kimai, timetracking, opensource, installation
Published: 2019-05-12 13:33:44

---
title: Time Tracking: Kimai2 0.9 on OpenBSD
published: true
description: Kimai is time-tracking app. It's open source, published under MIT license, and based on the latest PHP Symfony. I'll show how to install Kimai2 in this post.
tags: kimai, time tracking, open source, installation
cover_image: https://thepracticaldev.s3.amazonaws.com/i/rmxvn7gjx8f3ajpaelby.png
series: Time Tracking - Kimai on OpenBSD
canonical_url: https://dev.to/nabbisen/time-tracking-kimai2-1-0-on-openbsd-9k
---

## Introducation

[Kimai](https://www.kimai.org/) is open source time-tracking app.
There are two major versions: [Kimai1](https://github.com/kimai/kimai), which is [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html) licensed, and [Kimai2](https://github.com/kevinpapst/kimai2), which is [MIT](https://opensource.org/licenses/MIT) licensed.

In this post, I'll show how to install Kimai2, the latest.
It is based on [Symfony](https://symfony.com/), the [PHP](https://php.net) robust framework.
Besides, Kimai2 is great to [keep up the Symfony's updates](https://github.com/kevinpapst/kimai2/pull/710) :)

#### Environment

- OS: [OpenBSD](https://www.openbsd.org/) 6.5
- Database: [MariaDB](https://mariadb.org/) 10.0
- Web Server: [httpd](https://man.openbsd.org/httpd.8)
- App Server: [PHP](https://php.net/) 7.2
    - CGI: [PHP-FPM](https://php-fpm.org/)
    - Package Manager: [Composer](https://getcomposer.org/)
- Time-Tracking App: Kimai2 0.9

## Tutorial

The official installation manual is [here](https://www.kimai.org/documentation/installation.html).

#### Requirements

First of all, you have to have:

- [httpd as web server](https://dev.to/nabbisen/setting-up-openbsds-httpd-web-server-4p9f)
- [php-fpm](https://dev.to/nabbisen/php-fpm-on-openbsd-2iof)
- PHP [Composer](https://dev.to/nabbisen/almost-php-72-composer-with-openbsd-64-100o)
- [MariaDB as database server](https://dev.to/nabbisen/installing-mariadb-server-on-openbsd-5lm)

Additionally, [HTTPS is recommended](https://dev.to/nabbisen/lets-encrypt-certbot-for-openbsds-httpd-3ofd).

Well, All the links in this section are to the tutorials.

#### DB server

Create database and user:

```sql
CREATE DATABASE <database> CHARACTER SET = 'utf8mb4';
GRANT ALL PRIVILEGES ON <database>.* TO <dbuser> IDENTIFIED BY '<dbpass>';
```

#### App server

Get the package:

```console
$ git clone -b 0.9 --depth 1 https://github.com/kevinpapst/kimai2.git
$ cd kimai2/
```

Then modify the permissions:

```console
# chown -R :www .
# chmod -R g+r .
# chmod -R g+rw var/
```

Also configure the system:

```console
$ cp -p .env.dist .env
$ nvim .env
```

Here is where to change at least in `.env`:

```diff
- APP_SECRET=change_this_to_something_unique
+ APP_SECRET=<some_salt_key_long_enough>
...
- DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/kimai.sqlite
+ DATABASE_URL=mysql://<dbuser>:<dbpass>@<dbhost>:<dbport>/<database>
```

Let's install via Composer.
Using `php-7.2 /usr/local/libexec/composer.phar` is the trick for OpenBSD installation.

```console
$ php-7.2 /usr/local/libexec/composer.phar install --no-dev --optimize-autoloader
```

The result is:

```console
Loading composer repositories with package information
Installing dependencies from lock file
Package operations: 138 installs, 0 updates, 0 removals
  - Installing ocramius/package-versions (1.4.0): Downloading (100%)         
  - Installing kimai/kimai2-composer (0.1): Downloading (100%)         
  - Installing symfony/flex (v1.2.3): Downloading (100%)         

Prefetching 101 packages 🎶 💨
  - Downloading (100%)

  - Installing beberlei/doctrineextensions (v1.2.0): Loading from cache
...
  - Installing white-october/pagerfanta-bundle (v1.2.4): Loading from cache
Generating optimized autoload files
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Executing script cache:clear [OK]
Executing script assets:install [OK]
```

Then create schema in the database created below:

```console
$ php-7.2 bin/console doctrine:schema:create
```

The result is:

```console
 !                                                                                                                      
 ! [CAUTION] This operation should not be executed in a production environment!                                         
 !                                                                                                                      

 Creating database schema...

                                                                                                                        
 [OK] Database schema created successfully!
```

Here you will catch the warning above.
[The official document says](https://www.kimai.org/documentation/installation.html#recommended-setup):

> You can safely ignore the message: This operation should not be executed in a production environment!

Well, let's go ahead:

```console
$ php-7.2 bin/console cache:warmup --env=prod
```

The result is:

```console
 // Warming up the cache for the prod environment with debug false                                                      

                                                                                                                        
 [OK] Cache for the "prod" environment (debug=false) was successfully warmed.                                           
```

The system is now almost ready.
Create a user as the system administrator:

```console
$ php-7.2 bin/console kimai:create-user <username> <email-address> ROLE_SUPER_ADMIN
```

The result is:

```console
Please enter the password: 
                                                                                                                        
 [OK] Success! Created user: <username>
```

The last step is preparing web server.
Add the definition below to [`/etc/httpd.conf`](https://man.openbsd.org/httpd.conf.5):

```apache
server "<fqdn>" {
        listen on $ext_addr port 80
        block return 301 "https://$SERVER_NAME$REQUEST_URI"
}
server "<fqdn>" {
        listen on $ext_addr tls port 443
        tls {
                certificate     "/etc/letsencrypt/live/<fqdn>/fullchain.pem"
                key             "/etc/letsencrypt/live/<fqdn>/privkey.pem"
        }
        # create unique log files (optional):
        log {
                access  "<fqdn>-access.log"
                error   "<fqdn>-error.log"
        }
 
        # the document root is the directory named `public`:
        root "/<...>/kimai2/public"
        directory index index.php
 
        location "/*.php" { 
                fastcgi socket "/run/php-fpm.sock"
        } 
        location "/*.php[/?]*" {
                fastcgi socket "/run/php-fpm.sock"
        }
        # if directories are accessed to, call `index.php` with url parameter:
        location match "^/(.*)/[^\.]+/?$" {
                fastcgi socket "/run/php-fpm.sock"
                request rewrite "/index.php/%1"
        }
}
```

Restart it:

```console
# rcctl restart httpd
```

## Conclusion

Now all servers, database/app/web, are ready and listening.
Let's access to \<fqdn\> via any web browser:

![login form](https://thepracticaldev.s3.amazonaws.com/i/orsmvc14j52izbc40ag3.png)

![succeeded](https://thepracticaldev.s3.amazonaws.com/i/0lg0pq8klf2o3by4u65t.png)

Voilà 😆
I like this simple UI 🥳

Thank you for your reading.
Happy computing.