# How to install Gotify with Caddy In this guide I assume you want to use SQLite as storage mechanism. I used Ubuntu 18.04 but there should be no real differences between the different versions/distributions as long as it has systemd installed. All commands are executed as `root`. If you do not want to do this, prefix them with `sudo [command]`. You'll need the tool `unzip`. If you didn't install it yet or don't know if it is installed just execute `apt install -y unzip`. Parts of this guide are taken from [this](https://github.com/caddyserver/caddy/tree/master/dist/init/linux-systemd) guide and are modified for Gotify. ## 1. Decide for a install location I used the following paths: ```text App: /opt/gotify/ Config: /opt/gotify/config.yml Data: /opt/gotify/data/ ``` You of course be more compliant with the linux directories and use this structure: ```text App: /usr/local/bin/gotify Config: /etc/gotify/config.yml Data: /var/lib/gotify/ ``` Choose what you want and look for placeholders and replace the values appropiatly in the config files/commands we are using throughout this guide. Now for my approach we would create the directory like this, as I prefer to have all server applications in the `/opt` directory: ```bash mkdir -p /opt/gotify cd /opt/gotify ``` ## 2. Download Gotify First you have to get the download link to the binary of your architecture. Find the newest release [here](https://github.com/gotify/server/releases/latest) and replace ``. Download the release package to gotify-download.zip and unzip it. ```bash wget -O gotify-download.zip unzip gotify-download.zip ``` Rename the executable file to a more intuitive name and set permissions. ```bash mv gotify-- gotify sudo chown root:root gotify sudo chmod 755 gotify ``` Create a group and user for running the app. ```bash groupadd -r gotify useradd -M -d /opt/gotify -s /sbin/nologin -r -g gotify gotify ``` ## 3. Setup gotify configuration Put your configuration into the configuration file `config.yml`. It does not exist yet so you need to create it. Here is the configuration I used. Remember to **change the password**! Also for Caddy the port needs to be somewhat other than 80 or 443. I chose 3000 as its free on my machine but you might change it if you want to or the port is already in use. You might also change the paths according to your desired directory structure. ```yaml server: listenaddr: "127.0.0.1" # the address to bind on, leave empty to bind on all addresses port: 3000 # the port for the http server ssl: enabled: false # if https should be enabledeave empty to bind on all addresses letsencrypt: enabled: false # if the certificate should be requested from letsencrypt responseheaders: # response headers are added to every response (default: none) Access-Control-Allow-Origin: "*" Access-Control-Allow-Methods: "GET,POST" database: # see below dialect: sqlite3 connection: data/gotify.db defaultuser: # on database creation, gotify creates an admin user (these values will only be used for the first start, if you want to edit the user after the first start use the WebUI) name: admin # the username of the default user pass: somesupersecurepassword123!!! # the password of the default user passstrength: 10 # the bcrypt password strength (higher = better but also slower) uploadedimagesdir: data/images # the directory for storing uploaded images pluginsdir: data/plugins # the directory where plugin resides (leave empty to disable plugins) ``` Then assign the correct permissions to the configuration file. ```bash chown root:root config.yml chmod 644 config.yml ``` Create the data directory with correct permissions. ```bash mkdir /opt/gotify/data chown -R gotify:gotify /opt/gotify/data chmod -R 755 /opt/gotify/data ``` You can test if you set it up correctly until now by executing this command: ```bash sudo -u gotify ./gotify ``` If you see something like `server started` and no errors everything is fine and you can exit again using `Ctrl + C`. ## 4. Setup systemd service Save this systemd service to `/etc/systemd/system/gotify.service`. Remember to replace the paths according to your situation if you wanted to change them. ```text [Unit] Description=Gotify Push Notification Server Documentation=https://gotify.net/docs After=network-online.target Wants=network-online.target systemd-networkd-wait-online.service StartLimitIntervalSec=14400 StartLimitBurst=10 [Service] Restart=on-abnormal User=gotify Group=gotify WorkingDirectory=/opt/gotify ExecStart=/opt/gotify/gotify PrivateTmp=true ProtectSystem=full ReadWritePaths=/opt/gotify/data ReadWriteDirectories=/opt/gotify/data TimeoutStopSec=5s [Install] WantedBy=multi-user.target ``` Set the appropiate permissions for the service file. ```bash chown root:root /etc/systemd/system/gotify.service chmod 644 /etc/systemd/system/gotify.service ``` Tell systemd to reload and run it. ```bash systemctl daemon-reload systemctl start gotify.service ``` You can verify if it worked by executing the following command and seeing the same output like in the previous test. ```bash systemctl status gotify.service ``` If you want to enable the autostart after boot you can enable it like this: ```bash systemctl enable gotify.service ``` ## 5. Setup caddy Add the following to your `Caddyfile`. If you set another port than 3000 remember to change it here too. ```text { proxy / localhost:3000 { transparent websocket } } ``` Restart caddy and everything should be done. ```bash systemctl restart caddy ``` Test by going to `https:///`. ## Notes - Consider removing the admin password from the `config.yml` or change to another to prevent forgetting to change and other people getting access to the admin panel.