• Create a system-user

      SYNAPSE_USER_DIR=/var/lib/synapse
      sudo adduser --system synapse --home $SYNAPSE_USER_DIR/synapse
    
  • Install a Python3 virtual environment and Synapse

      SYNAPSE_DIR=$SYNAPSE_USER_DIR/synapse
      sudo -u synapse mkdir -p $SYNAPSE_DIR
      sudo -u synapse python3 -m venv $SYNAPSE_DIR/.venv
      sudo -u synapse $SYNAPSE_DIR/.venv/bin/pip install matrix-synapse
      sudo -u synapse $SYNAPSE_DIR/.venv/bin/pip install psycopg2-binary
    
  • Create and edit the configuration file. See https://matrix-org.github.io/synapse/develop/setup/installation.html for details.

      sudo -u synapse /.venv/bin/python3 -m synapse.app
    

    Incomplete

    Alternatively, copy the file from another installation and edit it

  • Create and install a systemd .service file

      (
      cat <<EOF
      [Unit]
      Description=Synapse Matrix server
      Documentation=https://www.matrix.org
      After=network.target
      #After=postgresql.service
    
      [Service]
      Type=notify
      NotifyAccess=main
      Restart=on-abort
    
      User=synapse
      Group=nogroup
      WorkingDirectory=$SYNAPSE_DIR
      ExecStart=$SYNAPSE_DIR/.venv/bin/python3 -m synapse.app.homeserver --config-path=$SYNAPSE_DIR/homeserver.yaml
      ExecReload=/bin/kill -HUP $MAINPID
      SyslogIdentifier=matrix-synapse
    
      [Install]
      WantedBy=multi-user.target
      EOF
      ) | sudo tee /etc/systemd/system/matrix-synapse.service          
    

    Derived from https://github.com/matrix-org/synapse/blob/master/contrib/systemd/matrix-synapse.service

  • Start service

      sudo systemctl start matrix-synapse
    
  • Verify that it has started

      systemctl status
      journalctl -u matrix-synapse
    
  • Set it to start automatically

      sudo systemctl enable matrix-synapse