Rainloop Webmail on OpenBSD 6.9
Tags: rainloop, mailserver, webmail, openbsd
Published: 2021-08-16 08:13:03

## Summary

[Rainloop](https://www.rainloop.net/) is a "simple, modern & fast web-based email client", written in [PHP](https://www.php.net/). It's also [open source](https://github.com/RainLoop/rainloop-webmail) [licensed under AGPL v3](https://github.com/RainLoop/rainloop-webmail/blob/master/LICENSE).
I installed it in [OpenBSD](https://www.openbsd.org/) server. It was really simple.

### Environment

- OS: OpenBSD 6.9
- Web server: OpenBSD [httpd](https://man.openbsd.org/httpd.5)
- App server: [PHP-FPM](https://www.php.net/manual/en/install.fpm.php) based on PHP 7.4
- Webmail: Rainloop 1.16

### References

- How to run OpenBSD httpd

{% post nabbisen/setting-up-openbsds-httpd-web-server-4p9f %}

- How to run PHP-FPM on OpenBSD

{% post nabbisen/php-fpm-on-openbsd-2iof %}

## Installation steps

### Get the package

First, get [the latest package](https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip). There are two ways: [its official website](https://www.rainloop.net/try-now/) or [GitHub releases](https://github.com/RainLoop/rainloop-webmail/releases/). Here, the former is adopted.

Prepare the document root:

```console
$ cd /var/www
$ mkdir <rainloop-dir>
$ cd <rainloop-dir>
```

Get the package:

```console
$ ftp https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip
```

`unzip` it:

```console
$ # doas pkg_add unzip # do beforehand if necessary
$ unzip rainloop-community-latest.zip
```

You will see:

```
$ ls
data/        index.php    rainloop/
```

Besides, all what to do in order to upgrade in the future will be to add "rainloop/v/\<next-version\>" and update "data/VERSION".

## Configure

Set the permissions for App server to access "data/":

```console
$ doas chown -R www: data
```

Configure httpd server via [httpd.conf](https://man.openbsd.org/httpd.conf.8):

```console
$ doas nvim /etc/httpd.conf
```

Edit it like below. __\<fqdn\>__ means the host aka "_https://_ __some.domain__ _/..._"
Be careful not to allow web access to "data/". `location "/data/*" { block }` is important.

```apache
server "<fqdn>" {
    listen on $ext_addr tls port 443
    tls {
        certificate "/etc/ssl/*.pem"
        key         "/etc/ssl/private/*.key"
    }
    log {
        access  "<fqdn>-access.log"
        error   "<fqdn>-error.log"
    }

    root "/<rainloop-dir>"
    directory index index.php

    # security
    location "*/.git*"              { block }
    ## app specific (ref: https://www.rainloop.net/docs/permissions/ )
    location "/data/*"              { block }
    # robots.txt
    location "/robots.txt"          { pass }

    location "/*.php" {
        fastcgi socket "/run/php-fpm.sock"
    }
}
```

Restart the daemon:

```console
$ doas rcctl restart httpd
```

Finished.

## Conclusion

Now you can access the webmail via web browsers:

![user login](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1e2c3yq5kopsptg0y043.png)

Well, custom domains are not allowed by default. It is able to configure them in [the admin panel](https://www.rainloop.net/docs/configuration/). Also, you must __change admin id/password__ there.