Skip to content

Setting up a Synapse Server

Aaron Raimist edited this page Dec 3, 2018 · 2 revisions

Synapse Installation

Synapse is the reference Python/Twisted Matrix homeserver implementation.

System requirements:

  • POSIX-compliant system (tested on Linux & OS X)
  • Python 2.7
  • At least 1GB of free RAM if you want to join large public rooms like #matrix:matrix.org

Installing from source

(Prebuilt packages are available for some platforms - see Platform-Specific Instructions.)

Synapse is written in Python but some of the libraries it uses are written in C. So before we can install Synapse itself we need a working C compiler and the header files for Python C extensions.

Installing prerequisites on Ubuntu or Debian:

sudo apt-get install build-essential python2.7-dev libffi-dev \
                     python-pip python-setuptools sqlite3 \
                     libssl-dev python-virtualenv libjpeg-dev libxslt1-dev

Installing prerequisites on ArchLinux:

sudo pacman -S base-devel python2 python-pip \
               python-setuptools python-virtualenv sqlite3

Installing prerequisites on CentOS 7 or Fedora 25:

sudo yum install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
                 lcms2-devel libwebp-devel tcl-devel tk-devel redhat-rpm-config \
                 python-virtualenv libffi-devel openssl-devel
sudo yum groupinstall "Development Tools"

Installing prerequisites on Mac OS X:

xcode-select --install
sudo easy_install pip
sudo pip install virtualenv
brew install pkg-config libffi

Installing prerequisites on Raspbian:

sudo apt-get install build-essential python2.7-dev libffi-dev \
                     python-pip python-setuptools sqlite3 \
                     libssl-dev python-virtualenv libjpeg-dev
sudo pip install --upgrade pip
sudo pip install --upgrade ndg-httpsclient
sudo pip install --upgrade virtualenv

Installing prerequisites on openSUSE:

sudo zypper in -t pattern devel_basis
sudo zypper in python-pip python-setuptools sqlite3 python-virtualenv \
               python-devel libffi-devel libopenssl-devel libjpeg62-devel

Installing prerequisites on OpenBSD:

doas pkg_add python libffi py-pip py-setuptools sqlite3 py-virtualenv \
             libxslt jpeg

To install the Synapse homeserver run:

virtualenv -p python2.7 ~/.synapse
source ~/.synapse/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
pip install matrix-synapse

This installs Synapse, along with the libraries it uses, into a virtual environment under ~/.synapse. Feel free to pick a different directory if you prefer.

This Synapse installation can then be later upgraded by using pip again with the update flag:

source ~/.synapse/bin/activate
pip install -U matrix-synapse

In case of problems, please see the Troubleshooting section below.

There is an offical synapse image available at https://hub.docker.com/r/matrixdotorg/synapse/tags/ which can be used with the docker-compose file available at contrib/docker. Further information on this including configuration options is available in the README on hub.docker.com.

Alternatively, Andreas Peters (previously Silvio Fricke) has contributed a Dockerfile to automate a synapse server in a single Docker image, at https://hub.docker.com/r/avhost/docker-matrix/tags/

Slavi Pantaleev has created an Ansible playbook, which installs the offical Docker image of Matrix Synapse along with many other Matrix-related services (Postgres database, riot-web, coturn, mxisd, SSL support, etc.). For more details, see https://github.com/spantaleev/matrix-docker-ansible-deploy

Platform-Specific Instructions

Debian

Matrix provides official Debian packages via apt from https://matrix.org/packages/debian/. Note that these packages do not include a client - choose one from https://matrix.org/docs/projects/try-matrix-now.html (or build your own with one of our SDKs :)

Fedora

Synapse is in the Fedora repositories as matrix-synapse:

sudo dnf install matrix-synapse

Oleg Girko provides Fedora RPMs at https://obs.infoserver.lv/project/monitor/matrix-synapse

OpenSUSE

Synapse is in the OpenSUSE repositories as matrix-synapse:

sudo zypper install matrix-synapse

SUSE Linux Enterprise Server

Unofficial package are built for SLES 15 in the openSUSE:Backports:SLE-15 repository at https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/

ArchLinux

The quickest way to get up and running with ArchLinux is probably with the community package https://www.archlinux.org/packages/community/any/matrix-synapse/, which should pull in most of the necessary dependencies. If the default web client is to be served (enabled by default in the generated config), https://www.archlinux.org/packages/community/any/python2-matrix-angular-sdk/ will also need to be installed.

Alternatively, to install using pip a few changes may be needed as ArchLinux defaults to python 3, but synapse currently assumes python 2.7 by default:

pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 ):

sudo pip2.7 install --upgrade pip

You also may need to explicitly specify python 2.7 again during the install request:

pip2.7 install https://github.com/matrix-org/synapse/tarball/master

If you encounter an error with lib bcrypt causing an Wrong ELF Class: ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly compile it under the right architecture. (This should not be needed if installing under virtualenv):

sudo pip2.7 uninstall py-bcrypt
sudo pip2.7 install py-bcrypt

During setup of Synapse you need to call python2.7 directly again:

cd ~/.synapse
python2.7 -m synapse.app.homeserver \
  --server-name machine.my.domain.name \
  --config-path homeserver.yaml \
  --generate-config

...substituting your host and domain name as appropriate.

FreeBSD

Synapse can be installed via FreeBSD Ports or Packages contributed by Brendan Molloy from:

  • Ports: cd /usr/ports/net-im/py-matrix-synapse && make install clean
  • Packages: pkg install py27-matrix-synapse

OpenBSD

There is currently no port for OpenBSD. Additionally, OpenBSD's security settings require a slightly more difficult installation process.

  1. Create a new directory in /usr/local called _synapse. Also, create a new user called _synapse and set that directory as the new user's home. This is required because, by default, OpenBSD only allows binaries which need write and execute permissions on the same memory space to be run from /usr/local.
  2. su to the new _synapse user and change to their home directory.
  3. Create a new virtualenv: virtualenv -p python2.7 ~/.synapse
  4. Source the virtualenv configuration located at /usr/local/_synapse/.synapse/bin/activate. This is done in ksh by using the . command, rather than bash's source.
  5. Optionally, use pip to install lxml, which Synapse needs to parse webpages for their titles.
  6. Use pip to install this repository: pip install matrix-synapse
  7. Optionally, change _synapse's shell to /bin/false to reduce the chance of a compromised Synapse server being used to take over your box.

After this, you may proceed with the rest of the install directions.

NixOS

Robin Lambertz has packaged Synapse for NixOS at: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/matrix-synapse.nix

Windows Install

If you wish to run or develop Synapse on Windows, the Windows Subsystem For Linux provides a Linux environment on Windows 10 which is capable of using the Debian, Fedora, or source installation methods. More information about WSL can be found at https://docs.microsoft.com/en-us/windows/wsl/install-win10 for Windows 10 and https://docs.microsoft.com/en-us/windows/wsl/install-on-server for Windows Server.

Security Note

Matrix serves raw user generated data in some APIs - specifically the content repository endpoints.

Whilst we have tried to mitigate against possible XSS attacks (e.g. https://github.com/matrix-org/synapse/pull/1021) we recommend running matrix homeservers on a dedicated domain name, to limit any malicious user generated content served to web browsers a matrix API from being able to attack webapps hosted on the same domain. This is particularly true of sharing a matrix webclient and server on the same domain.

See https://github.com/vector-im/vector-web/issues/1977 and https://developer.github.com/changes/2014-04-25-user-content-security for more details.

Continue to Configuring Synapse

Upgrading an existing Synapse

The instructions for upgrading synapse are in UPGRADE.rst. Please check these instructions as upgrading may require extra steps for some versions of synapse.