Matrix Synapse-1-3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

3/11/2020 Matrix Synapse [NaWiki]

Matrix Synapse
Matrix is an open standard for interoperable, decentralised, real-time communication over IP. It can be
used to power Instant Messaging, VoIP and Internet of Things communication - or anywhere you need a
standard HTTP API for publishing and subscribing to data whilst tracking the conversation history.

Synapse is a reference homeserver implementation from the core development team at matrix.org, written
in Python/Twisted.

In this guide, we will show you step-by-step how to install and configure Synapse on Ubuntu 18.04. We
will configure Synapse and the Nginx web server as a reverse proxy for it and implement the HTTPS
connection between clients and the front-end Nginx web server. We will also show how to set up a
PostgreSQL database for better performance.

This guide explains one way to setup a Synapse server. There are many other correct ways to setup a
Matrix server and that is the reason why there are so many guides. Feel free to choose the guide that suits
your setup the best.

How to install Synapse on Ubuntu 18.04 LTS

Prerequisites
Ubuntu 18.04 secured with basic security
Root privileges
A domain name for your server

What we will do
Update and Upgrade System
Install Synapse
Configure Synapse
Generate SSL certificates using Let's Encrypt
Install and configure Nginx as a reverse proxy
Install and configure Postgres instead of SQLite (optional but highly recommended, SQLite should
not be used in production)
Setup UFW Firewall
Create a new Matrix user on your server
Check federation
https://www.natrius.eu/dokuwiki/doku.php?id=digital:server:matrixsynapse 1/13
3/11/2020 Matrix Synapse [NaWiki]

Test the installation

Step 1 - Update and Upgrade System


Read the whole tutorial before starting to install the server.

Login to your Ubuntu server and add the repository key to make sure any installations and updates have
been signed by the developers and to stop any unauthorized packages from being installed on your server.

sudo apt install -y lsb-release wget apt-transport-https


sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix
echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packag

Update the repository and upgrade all packages using the apt command below.

sudo sh -c 'apt update && apt upgrade'

Step 2 - Install Synapse


Install matrix-synapse using the apt command as below. (You can add the option -y to assume “yes” as
answer to all prompts and run non-interactively) The name is matrix-synapse-py3 because there is
already another package name synapse .There is also a matrix-synapse package available but this
uses Python 2 and it will stop being updated soon as Python 2 reaches end of life.

sudo apt install matrix-synapse-py3

During the installation, it will ask you about the matrix server name - type in your domain
example.com . (We will not use matrix.example.com , because we also don't use
mail.example.com for our E-Mails. This will work with well.known, SRV-records and nginx.

Don't leave the hostname blank during setup.

If you want to provide the team with information about your setup with an anonymous data report, choose
'Yes', otherwise leave it at 'No'.

When the Synapse installation is complete, start the service and enable it to launch everytime at system
boot.

sudo systemctl start matrix-synapse.service


sudo systemctl enable matrix-synapse.service

https://www.natrius.eu/dokuwiki/doku.php?id=digital:server:matrixsynapse 2/13
3/11/2020 Matrix Synapse [NaWiki]

Synapse is now up and running using the default configuration on port '8008' and '8448'. Check the open
ports using netstat command.

sudo ss -plntu

Set up well.known

On your webserver a file at /.well-known/matrix/server has to be set up with the following


content

{
"m.server": "synapse.example.com:443"
}

Where / is the root of your webserver. So if you navigate to


https://example.com/.well-known/matrix.server it may try to download the server file
or show it directly.

Set up SRV

By setting an SRV record in your DNS provider, it is possible to tell other matrix servers where to connect
to the server, pointing them to the correct hostname and port, in this example the default port (8448) is still
used:

_matrix._tcp.example.com. 3600 IN SRV 10 5 443 synapse.example.com.

There is still an A record needed, pointing to the IP-addess of synapse on the subdomain
(matrix.example.com). This way others can add your user with @user:example.com instead of
@user:matrix.example.com .

Step 3 - Configure Synapse


After the Synapse installation, we will configure it to run under the local IP address, disable Synapse
registration, and enable the registration-shared-secret.

Before editing the home server configuration, we need to generate the shared secret key with the following
command.

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1

And you will get a generated key. We will disable the registration for now and then copy the key into the
homeserver configuration file. To disable the Synapse registration, uncomment the
registration_shared_secret (Delete the # and don't leave a whitespace)
https://www.natrius.eu/dokuwiki/doku.php?id=digital:server:matrixsynapse 3/13

You might also like