Install a Matrix Synapse homeserver

Synapse installs on the Ubuntu 24.04 image from the official packages.matrix.org repository, runs on port 8008 behind Nginx with HTTPS, and stores its data in PostgreSQL. Choose your server_name first, because it becomes part of every user ID and cannot change later; then use .well-known delegation so IDs read @you:example.com while the server lives at matrix.example.com. P4 fits a small community.

Self-hosted apps guide, updated 2026-12-03

What is Synapse, and what does a homeserver do?

Matrix is an open protocol for chat, voice signalling and rooms that span many servers. A homeserver holds your users, their room history and their media, and federates with other homeservers so people on different servers share the same rooms. Synapse is the reference homeserver, written in Python, and the most widely deployed one.

The console has no Synapse image. Create a server from Ubuntu 24.04 and follow this guide: package repository, PostgreSQL, Nginx, delegation, a web client and the settings that keep the disk under control.

Which plan and city does a homeserver need?

Synapse memory grows with the number of rooms your users are in, and especially with large federated rooms that have thousands of members on other servers. Joining a few big public rooms costs more than a hundred users chatting among themselves.

UsePlanSpecs
Family or friends, small private roomsP21 vCPU, 2 GB RAM, 40 GB NVMe
Team or community, some federated roomsP42 vCPU, 4 GB RAM, 80 GB NVMe
Hundreds of users or many large public roomsP84 vCPU, 8 GB RAM, 160 GB NVMe
Steady CPU for busy federation trafficD82 vCPU, 8 GB RAM, 80 GB NVMe

Put the server near your users; federation traffic to other servers is not sensitive to a few extra milliseconds. Every one of the 15 cities carries the same price.

What is the difference between server_name and the hostname?

server_name is the domain in user IDs and room aliases: with example.com a user is @anna:example.com. It is written into the database and every event; you cannot rename it later without starting over. The hostname is where Synapse actually answers, for example matrix.example.com.

Most people want short IDs on the main domain while the website for example.com stays wherever it is. Delegation solves that: two small JSON files on https://example.com/.well-known/matrix/ tell clients and other servers to talk to matrix.example.com. If you are fine with IDs like @anna:matrix.example.com, set server_name to the hostname and skip delegation.

DNS: create A and AAAA records for matrix.example.com pointing to 203.0.113.10 and 2001:db8:1234:5678::1. Add element.example.com the same way if you host the web client. See pointing a domain.

How do you install Synapse from the official repository?

apt update && apt install -y lsb-release wget apt-transport-https
wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/matrix-org.list
apt update
apt install -y matrix-synapse-py3

The installer asks for the server name (type example.com, or the hostname if you skip delegation) and whether to report anonymous usage statistics. It writes the name to /etc/matrix-synapse/conf.d/server_name.yaml; the main config is /etc/matrix-synapse/homeserver.yaml. Synapse starts at once and listens on 127.0.0.1:8008 and ::1. Check with:

systemctl status matrix-synapse
curl -s http://127.0.0.1:8008/_matrix/client/versions

The second command prints a JSON list of supported client API versions. This repository builds for Debian and Ubuntu on amd64 and arm64; on Rocky or Alma, Synapse is installed from PyPI into a virtualenv or run as a container instead.

How do you switch the database to PostgreSQL?

The package starts on SQLite, which is meant for testing only. Switch before creating any users:

apt install -y postgresql
sudo -u postgres createuser --pwprompt synapse_user
sudo -u postgres createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse

The C locale is required; Synapse refuses to start on a database with another collation. Create /etc/matrix-synapse/conf.d/database.yaml:

database:
  name: psycopg2
  args:
    user: synapse_user
    password: your-db-password
    dbname: synapse
    host: 127.0.0.1
    cp_min: 5
    cp_max: 10

Then systemctl restart matrix-synapse and watch journalctl -u matrix-synapse -f for the schema setup. More about running PostgreSQL on a VPS is in the databases use case.

How do you set up Nginx, HTTPS and federation on 8448 or by delegation?

Other homeservers find yours in one of two ways: by connecting to port 8448 on the server_name host, or by reading /.well-known/matrix/server, which can send them to port 443 instead. Delegation lets you keep everything on 443. The Nginx block for the homeserver:

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    listen 8448 ssl default_server;
    listen [::]:8448 ssl default_server;
    server_name matrix.example.com;
    # ssl_certificate lines are added by certbot
    location ~ ^(/_matrix|/_synapse/client) {
        proxy_pass http://127.0.0.1:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        client_max_body_size 50M;
        proxy_http_version 1.1;
    }
}

Get the certificate with certbot --nginx -d matrix.example.com (start from a plain port 80 block, as in Nginx with HTTPS). The 8448 listeners are only needed without delegation. For delegation, serve these two files from the web server of example.com with Content-Type: application/json:

# https://example.com/.well-known/matrix/server
{ "m.server": "matrix.example.com:443" }

# https://example.com/.well-known/matrix/client
{ "m.homeserver": { "base_url": "https://matrix.example.com" } }

The client file also needs the header Access-Control-Allow-Origin: * so web clients can read it. Test federation with the public Matrix federation tester by entering example.com.

How do you host Element web and create users?

Element web is a static site. Download the current release tarball from the Element project release page, unpack it and point Nginx at it:

mkdir -p /var/www/element && cd /var/www/element
tar xzf /root/element-vX.Y.Z.tar.gz --strip-components=1
cp config.sample.json config.json

In config.json set default_server_config.m.homeserver.base_url to https://matrix.example.com and server_name to example.com. Serve the folder from a server block for element.example.com with its own certificate. Hosting Element on a different hostname than Synapse is recommended for browser security.

Registration. Open sign-up is off by default (enable_registration: false), which is right for most servers: open registration without email or captcha checks attracts spam accounts. Create users yourself. Add a shared secret in /etc/matrix-synapse/conf.d/registration.yaml:

registration_shared_secret: "output-of-openssl-rand-hex-32"

Restart, then run register_new_matrix_user -c /etc/matrix-synapse/conf.d/registration.yaml http://127.0.0.1:8008 and answer yes to admin for your own account. For a community, token-based sign-up (registration_requires_token: true with tokens made through the admin API) is a good middle ground.

Which firewall ports does a homeserver use?

ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 8448/tcp   # only without .well-known delegation
ufw enable

Port 8008 stays on localhost. Voice and video calls between two people need a TURN server such as coturn, which adds UDP 3478 and a relay port range; group calls use a separate media service. See the firewall guide.

Why does the media store grow, and how do you control it?

Every image, file and avatar your users upload is stored in /var/lib/matrix-synapse/media, and so is a cached copy of remote media your users view in federated rooms. Remote media is usually the larger share on servers that join busy public rooms. Check it with du -sh /var/lib/matrix-synapse/media.

Set retention so cached remote files expire on their own, in /etc/matrix-synapse/conf.d/media.yaml:

media_retention:
  remote_media_lifetime: 30d
max_upload_size: 50M

Remote media can always be fetched again from the origin server, so a short lifetime is safe. The database grows too, mainly from state of large rooms; leaving rooms nobody reads and running PostgreSQL VACUUM during quiet hours keeps it in check. When the NVMe disk gets tight, migrate to a bigger plan as in moving to a bigger plan.

How do you update, back up and troubleshoot Synapse?

Updates arrive through apt: apt update && apt upgrade installs new Synapse releases from the repository and restarts the service. Read the upgrade notes for releases that drop old PostgreSQL or Python versions.

Backups. The parts you cannot recreate are the database, the signing key and the local media:

sudo -u postgres pg_dump -Fc synapse > /root/synapse.dump
restic backup /root/synapse.dump /etc/matrix-synapse /var/lib/matrix-synapse/media/local_content

The signing key lives in /etc/matrix-synapse/homeserver.signing.key; losing it forces other servers to re-learn your keys. The disk backup add-on ($2.41 per month on P4) gives 7 daily copies of the whole server as a second layer.

Troubleshooting. Federation tester reports errors: check that the .well-known files return JSON on HTTPS and that 443 or 8448 answers with a valid certificate for the right name. "Incorrect collation" at start: the database was created without --locale=C; recreate it. Clients cannot find the server: the client well-known file is missing the CORS header. High memory: lower caches.global_factor in a conf.d file and leave the biggest public rooms.

Questions about this guide

Can I change the server_name later?

No. User IDs and events carry it permanently. Decide before the first user is created; delegation lets you keep short IDs anyway.

Is SQLite enough for a tiny server?

Synapse treats SQLite as a testing option. Use PostgreSQL from day one; migrating later needs the synapse_port_db tool and downtime.

Does Synapse run on Arm?

Yes, the official repository has arm64 builds, so A8 in Frankfurt, Nuremberg, Helsinki or Amsterdam is a good fit.

Do I need port 8448 open?

Only if you do not publish /.well-known/matrix/server. With delegation all federation runs on 443.

Can Synapse send email for password resets?

Yes, with an email section that uses an authenticated SMTP relay on port 587. Outgoing port 25 is opened only on request to support.

Which client should my users install?

Any Matrix client works. Point them at example.com as the server; delegation sends them to the right host.