# Packaged server installation

This is essentially Trilium sources + node modules + node.js runtime packaged into one 7z file.

## Steps

- SSH into your server
- use `wget` (or `curl`) to download latest `TriliumNextNotes-Server-[VERSION]-linux-x64.tar.xz` (notice `-Server` suffix) on your server.
- unpack the archive, e.g. using `tar -xf -d TriliumNextNotes-Server-[VERSION]-linux-x64.tar.xz`
- `cd trilium-linux-x64-server`
- `./trilium.sh`
- you can open the browser and open http://[your-server-hostname]:8080 and you should see Trilium initialization page

The problem with above steps is that once you close the SSH connection, the Trilium process is terminated. To avoid that, you have two options:

- Kill it (with e.g. `Ctrl` + `C`) and run again like this: `nohup ./trilium &`.
- Configure systemd to automatically run Trilium in the background on every boot

## Configure Trilium to auto-run on boot with systemd

- After downloading, extract and move Trilium:

    tar -xvf TriliumNextNotes-Server-[VERSION]-linux-x64.tar.xz
    sudo mv trilium-linux-x64-server /opt/trilium

- Create the service:

    sudo nano /etc/systemd/system/trilium.service

- Paste this into the file (replace the user and group as needed):

    [Unit]
    Description=Trilium Daemon
    After=syslog.target network.target

    [Service]
    User=xxx
    Group=xxx
    Type=simple
    ExecStart=/opt/trilium/trilium.sh
    WorkingDirectory=/opt/trilium/

    TimeoutStopSec=20
    # KillMode=process leads to error, according to https://www.freedesktop.org/software/systemd/man/systemd.kill.html
    Restart=always

    [Install]
    WantedBy=multi-user.target

- Save the file (CTRL-S) and exit (CTRL-X)
- Enable and launch the service:

    sudo systemctl enable --now -q trilium

- You can now open a browser to http://[your-server-hostname]:8080 and you should see the Trilium initialization page.

## Common issues

### Outdated glibc

    Error: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /var/www/virtual/.../node_modules/@mlink/scrypt/build/Release/scrypt.node)
        at Object.Module._extensions..node (module.js:681:18)
        at Module.load (module.js:565:32)
        at tryModuleLoad (module.js:505:12)

If you get an error like this, you need to either upgrade your glibc (typically by upgrading to up-to-date distribution version) or use some other server installation method.

## TLS

Don't forget to configure TLS, which is required for secure usage!