+-----------------------------------------------------------------------
| Running icinga-web2 on OpenBSD
+-----------------------------------------------------------------------

Web User Interface
==================

The main Icinga 2 program should be configured first. Several features
are required for use with Icinga Web 2: either an "ido" database module
or "livestatus", and also "command". Consult Icinga documentation
about using "icinga2 feature enable" to do this, for configuration
details, database schema, etc.

The majority of Icinga Web 2 configuration is web-based and simple,
but a few things will need to be setup FIRST.

- Consult PHP package documentation to configure PHP and enable modules.

- If using PostgreSQL, install and enable php-pgsql and php-pdo_pgsql.

- If using php-fpm, configure it to run scripts as the _icingaweb2
user, and set the /tmp directory. You may add this to /etc/php-fpm.conf:

[icingaweb2]
user = _icingaweb2
group = _icingaweb2
listen = /var/www/run/php-fpm-icingaweb2.sock
listen.owner = www
listen.group = www
listen.mode = 0660
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 5
chroot = /var/www
env[TMP] = /icinga-web2/tmp
env[TMPDIR] = /icinga-web2/tmp

(If instead of php-fpm you use Apache with mod_php, you will need to
add the userid running PHP scripts to the _icingaweb2 group).

- Configure your webserver to pass requests to icingaweb2's front
controller. An example for nginx (remember to "rcctl reload nginx"
after adding), using the above php-fpm section:

   location ~ ^/icingaweb2/index\.php(.*)$ {
       fastcgi_pass   unix:run/php-fpm-icingaweb2.sock;
       fastcgi_index index.php;
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME /icinga-web2/public/index.php;
       fastcgi_param ICINGAWEB_CONFIGDIR /etc/icingaweb2;
       fastcgi_param REMOTE_USER $remote_user;
   }

   location ~ ^/icingaweb2(.+)? {
       alias /var/www/icinga-web2/public;
       index index.php;
       try_files $1 $uri $uri/ /icingaweb2/index.php$is_args$args;
   }

For Apache httpd, configuration files are provided in
/var/www/conf/modules.sample that can be symlinked to /var/www/conf/modules.

If you use mod_php, use this:
   # ln -s ../modules.sample/icingaweb2.conf /var/www/conf/modules

Or if you use for php-fpm, use this:
   # ln -s ../modules.sample/icingaweb2.fpm.conf /var/www/conf/modules

And reload:
   # rcctl reload apache2

An example for base httpd(8), serving directly from the root using the
above php-fpm section:

   server "icinga.example.com" {
       listen on * tls port 443
       tls {
           certificate "/etc/ssl/icinga.example.com.crt"
           key "/etc/ssl/private/icinga.example.com.key"
       }

       root "/icinga-web2/public"
       directory index "index.php"
       location "*.php*" {
           fastcgi socket "/run/php-fpm-icingaweb2.sock"
           fastcgi param ICINGAWEB_CONFIGDIR "/etc/icingaweb2"
       }

       location not found "*" {
           request rewrite "/index.php?$QUERY_STRING"
       }
   }

- Using icingacli, create the config directory and a token to allow setup:

   # /var/www/icinga-web2/bin/icingacli setup config directory --group _icingaweb2
   # /var/www/icinga-web2/bin/icingacli setup token create

- Open the web interface http://localhost/icingaweb2/. Paste in the token
that was displayed on-screen in the above step and proceed to the web-based
part of the configuration.
