# Setup Trilium Notes On Arch Linux

[Trilium](https://github.com/zadam/trilium) is a self-hosted, single-user note taking application. Trilium server is a web application which provides responsive UI for note taking. The [desktop](https://github.com/zadam/trilium/wiki#choose-the-setup) client synchronises with the server. It does not have mobile app, but it has a [*mobile web frontend which is optimized for touch based devices - smartphones and tablets*](https://github.com/zadam/trilium/wiki/Mobile-frontend)*.*

In this post I will provide instruction for hosting the server application in Arch Linux.

Prerequisites:

* Docker is [installed](https://wiki.archlinux.org/title/docker) and running.
    
* Install [`docker-compose`](https://archlinux.org/packages/extra/x86_64/docker-compose/) package.
    
* Add yourself to `docker` user group.  
    `sudo usermod -a -G docker <username>`
    

# Prepare Docker Compose File

Create a `docker-compose.yaml` file. You can save it in any folder you like, mine is kept in `~/dev/docker/trilium/`.

```yaml
services:
  trilium:
    image: 'zadam/trilium:0.63.7'
    restart: always
    ports:
      - '8080:8080'
    volumes:
      - '~/.trilium-data:/home/node/trilium-data'
```

The container will be listening on port 8080. If you want to change the port number to 3000, set the `ports` configuration value to '3000:8080'.

I want the note data to be saved in `~/.trilium-data/`. If you prefer other location, change the `volumes` configuration value to '/path/to/your/folder:/home/node/trilium-data'.

# Create And Start Container

```bash
# Go to folder containing compose file
cd ~/dev/docker/trilium
docker-compose up -d && docker-compose logs -f
```

`docker-compose logs -f` command is optional. It will show the log output so that you can check if there is any error when launching the container. Once Trilium is running well, you can press Ctrl + C to exit from the logging.

Trilium shall be accessible by launching http://&lt;you-server-ip&gt;:8080 in browser. Choose "I'm a new user, ..." on the webpage, and it will guide you to setup a password and get started on note taking.

# Setup Apache Reverse Proxy

This setup is optional. I am running Trilium in my home server with Apache web server installed. Setting up a reverse proxy allows me to access Trilium remotely.

Apache virtual host config:

```apache
<VirtualHost *:80>
	ServerName www.mydomain.com

    RewriteEngine On
    RewriteCond %{HTTP:Connection} Upgrade [NC]
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteRule /(.*) ws://localhost:8080/$1 [P,L]

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
```

# References

* [Trilium Notes - Open Source, Self Hosted Notes with nth level Hierarchy and Power!](https://youtu.be/dP08hPg-TMA) by Awesome Open Source
    
* [Docker server installation](https://github.com/zadam/trilium/wiki/Docker-server-installation) by zadam
    
* [Apache proxy setup](https://github.com/zadam/trilium/wiki/Apache-proxy-setup) by zadam
