Time Tracking: Kimai2 1.0 on OpenBSD
Tags: kimai, symfony, timetracking, openbsd
Published: 2019-07-03 04:17:09

---
title: Time Tracking: Kimai2 1.0 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, symfony, time tracking, openbsd
cover_image: https://thepracticaldev.s3.amazonaws.com/i/52e7sufdt7udgbourh79.png
series: Time Tracking - Kimai on OpenBSD
---

## Introducation

[Kimai2 1.0 was released](https://github.com/kevinpapst/kimai2/releases/tag/1.0)!!

[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.3
    - CGI: [PHP-FPM](https://php-fpm.org/)
    - Package Manager: [Composer](https://getcomposer.org/)
- Time-Tracking App: Kimai2 1.0

## 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 I wrote.

#### DB server

Create database and user:

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

#### App server

Get the package:

```console
$ git clone -b 1.0 --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>
```

*Note: According to [Symfony's documentation](https://symfony.com/doc/current/reference/configuration/framework.html#secret), `secret` value "should be a series of characters, numbers and symbols chosen randomly and the recommended length is around 32 characters." I used [LastPass generator](https://www.lastpass.com/password-generator).*

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

```console
$ php-7.3 /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: 136 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.5): Downloading (100%)         
...
  - 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]
```

*Note: There was no need to create schema and tables, that was different from the way in [installing Kimai2 0.9](https://dev.to/nabbisen/time-tracking-kimai2-on-openbsd-2mk9).*

Well, let's go ahead:

```console
$ php-7.3 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.
Let's prepare the 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
```

Finally, access to your FQDN aka https://\<fqdn\>, and you can select "Register a new account" link:

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

*Besides, altenatively, you can create a user as the system administrator via command line*:

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

*The result is*:

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

## Conclusion

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

![screenshot](https://thepracticaldev.s3.amazonaws.com/i/5f1ueqlryin1318t3i5z.png)

Voilà 🥳
A nice time tracking app with clean UI good on mobile, simple menus and several ways to export timesheets is here!

Thank you for your reading.
Happy computing.