On this page
- What do you need to plan first?
- How do you install Synapse from the official repository?
- How do you switch the database to PostgreSQL?
- Which other settings matter?
- How do you put Nginx in front and delegate the domain?
- How do you add Element Web?
- How do you create users and send email notices?
- How do you keep Synapse healthy over time?
- What should you check when something fails?
- Questions
What do you need to plan first?
Decide on the server name before installing, because it becomes part of every user ID and cannot be changed later. Most people use the bare domain (example.net) for short IDs and host the server itself on matrix.example.net, linking the two with delegation. Element Web gets its own name, such as element.example.net.
- Memory: 2 GB runs a private server for family or a small team. Joining large public federated rooms pulls in a lot of state, so give it 4 GB or more if you plan to.
- OS: Ubuntu 24.04 or 22.04, Debian 12 or 13.
- DNS: A and AAAA records for
matrix.example.netandelement.example.net, and a web server answering forexample.net(it only needs to serve two JSON files).
How do you install Synapse from the official repository?
sudo apt install -y lsb-release wget apt-transport-https
sudo 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" \
| sudo tee /etc/apt/sources.list.d/matrix-org.list
sudo apt update
sudo apt install -y matrix-synapse-py3
apt policy matrix-synapse-py3The installer asks for the server name: enter example.net. It also asks about anonymous statistics; answer as you prefer. Configuration lives in /etc/matrix-synapse/homeserver.yaml, and any .yaml file you add to /etc/matrix-synapse/conf.d/ is read too, which keeps your changes apart from the packaged file.
How do you switch the database to PostgreSQL?
The package starts with SQLite, which is meant for testing only. Create a PostgreSQL role and a database with the C collation Synapse requires:
sudo apt install -y postgresql
sudo -u postgres createuser --pwprompt synapse_user
sudo -u postgres createdb --encoding=UTF8 --locale=C \
--template=template0 --owner=synapse_user synapseThen create /etc/matrix-synapse/conf.d/database.yaml:
database:
name: psycopg2
args:
user: synapse_user
password: the-password-you-typed
dbname: synapse
host: localhost
cp_min: 5
cp_max: 10Comment out the database: block for SQLite in homeserver.yaml so only one definition remains. Do this before anyone registers; moving later needs the port script. See the PostgreSQL guide for tuning.
Which other settings matter?
Create /etc/matrix-synapse/conf.d/server.yaml with the public URL, closed registration and a shared secret for creating accounts from the command line:
public_baseurl: https://matrix.example.net/
enable_registration: false
registration_shared_secret: paste-output-of-openssl-rand-hex-32
max_upload_size: 50MThe packaged listener already binds port 8008 to 127.0.0.1 and ::1 with x_forwarded: true, which is exactly right behind a proxy. Restart and look at the log:
sudo systemctl restart matrix-synapse
sudo systemctl status matrix-synapse --no-pager
sudo journalctl -u matrix-synapse -n 30 --no-pager
curl -s http://127.0.0.1:8008/_matrix/federation/v1/versionThe last command prints the server name and Synapse version as JSON.
How do you put Nginx in front and delegate the domain?
Two Nginx server blocks do the job. The first proxies Matrix traffic on matrix.example.net:
server {
listen 80;
listen [::]:80;
server_name matrix.example.net;
client_max_body_size 50M;
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;
proxy_http_version 1.1;
}
}The second goes into the existing server block for example.net and announces where the homeserver really lives, for other servers and for clients:
location = /.well-known/matrix/server {
default_type application/json;
return 200 '{"m.server": "matrix.example.net:443"}';
}
location = /.well-known/matrix/client {
default_type application/json;
add_header Access-Control-Allow-Origin *;
return 200 '{"m.homeserver": {"base_url": "https://matrix.example.net"}}';
}sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d matrix.example.net -d example.net
sudo ufw allow 'Nginx Full'With this delegation, federation runs over 443 and port 8448 can stay closed. Check with curl https://example.net/.well-known/matrix/server and with the federation tester published by the Matrix project.
How do you add Element Web?
Element Web is a static site, so Nginx just serves files. Download the latest release tarball from the project releases page:
VER=$(curl -s https://api.github.com/repos/element-hq/element-web/releases/latest | grep -m1 tag_name | cut -d'"' -f4)
echo "$VER"
cd /tmp
wget https://github.com/element-hq/element-web/releases/download/$VER/element-$VER.tar.gz
sudo mkdir -p /var/www/element
sudo tar xzf element-$VER.tar.gz -C /var/www/element --strip-components=1
sudo cp /var/www/element/config.sample.json /var/www/element/config.jsonIn config.json, set default_server_config so base_url is https://matrix.example.net and server_name is example.net. Then add a server block for element.example.net with root /var/www/element;, reload Nginx and run Certbot for that name. Serving Element from its own subdomain, separate from the homeserver, follows the project security advice.
How do you create users and send email notices?
With registration closed, create accounts with the shared secret:
register_new_matrix_user -c /etc/matrix-synapse/conf.d/server.yaml http://localhost:8008Answer yes to the admin question for your own account. Synapse can email notifications about unread messages and handle password resets. Do not count on port 25 (ask support through a ticket before planning direct mail); use an authenticated relay on port 587 as covered in the SMTP relay guide, in conf.d/email.yaml:
email:
smtp_host: smtp.relay.example.net
smtp_port: 587
smtp_user: matrix@example.net
smtp_pass: relay-password
require_transport_security: true
notif_from: "Matrix at example.net <matrix@example.net>"
enable_notifs: trueRestart Synapse after the change.
How do you keep Synapse healthy over time?
Updates come through apt, so sudo apt update && sudo apt upgrade keeps Synapse current; read the upgrade notes when a release mentions database changes. For Element, repeat the download with the new version and keep your config.json.
Back up the PostgreSQL database, the signing key and the media store:
sudo -u postgres pg_dump -Fc synapse > ~/synapse-$(date +%F).dump
sudo tar czf ~/synapse-files-$(date +%F).tar.gz /etc/matrix-synapse /var/lib/matrix-synapse/mediaThe signing key in /etc/matrix-synapse identifies your server to the federation; losing it causes trust problems with other servers. Large federated rooms make the database grow, and purging remote media through the admin API keeps disk use under control.
What should you check when something fails?
- Clients cannot find the server: the client
.well-knownfile is missing or lacks the CORS header. - Other servers cannot reach you:
/.well-known/matrix/serverreturns HTML instead of JSON, or the certificate does not covermatrix.example.net. - Synapse will not start: run
journalctl -u matrix-synapse; a YAML indentation error inconf.dis the usual cause. - High memory use: leave very large public rooms or move to a bigger plan.
For a simpler team chat, compare Mattermost. More ideas: self-hosting.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Matrix Synapse with Element
Can I change the server name later?
No. The server name is part of every user and room ID. Choose it carefully before the first registration.
Do I need port 8448 open?
Not with the .well-known/matrix/server delegation shown here, which sends federation traffic over 443.
Can people on other Matrix servers talk to my users?
Yes, federation is on by default. You can restrict it with federation_domain_whitelist for a private server.
Is end-to-end encryption supported?
Yes. Element enables encryption for private rooms by default; the server stores only encrypted message content for those rooms.
Do I have to use Element?
No. Any Matrix client can log in to your server. Element Web is a convenient browser option you can host yourself.
More in Self-hosted apps
- Nextcloud on Nginx
- ownCloud Infinite Scale
- Seafile file sync
- Vaultwarden password vault
- Passbolt team password manager
- Gitea Git hosting
- Forgejo Git server
- GitLab Community Edition
- Gogs Git service
- Wiki.js
- BookStack documentation
- Outline knowledge base
- Paperless-ngx documents
- n8n workflow automation
- Activepieces automation
- Plausible Analytics (Community Edition)
- Umami analytics
- Mattermost team chat
- Jitsi Meet video calls
- ONLYOFFICE Docs with Nextcloud
- HashiCorp Vault secrets server
- OpenBao secrets management
- Infisical secrets manager
- Authelia SSO and forward auth
- Zitadel identity platform
- VS Code in the browser (code-server)
- Joplin Server for notes sync
- Firefly III personal finance
- Snipe-IT asset tracking
- Odoo ERP on Ubuntu or Debian
- ERPNext with frappe_docker
- Dolibarr ERP and CRM with Nginx
- Penpot design tool with Docker
- Planka kanban boards
- Leantime project management
- Wekan boards with Docker
- Cal.com scheduling
- Chatwoot support inbox
- Mautic marketing automation
- DocuSeal document signing
- Metabase dashboards
- Appwrite backend server
- Self-hosted Supabase
- PocketBase backend
- RustDesk relay server
- Traccar GPS tracking
- Redmine project tracker
- The Lounge IRC client
- CyberChef data toolbox
- Typebot chat forms
- AFFiNE workspace
- Overleaf Community Edition
- Neko shared virtual browser
- imgproxy image resizing
- NetBox network inventory
- UVdesk help desk
- YetiForce CRM