Setting Up Synapse Matrix Server with Docker: A Complete Guide¶
Introduction to Synapse Matrix Server¶
Synapse Matrix Server provides a robust platform for secure, decentralized communication. It supports instant messaging, VoIP, and file transfers, making it an excellent choice for individuals and organizations looking for a private communication solution.
Deployment Steps for Synapse Matrix Server¶
This guide will walk you through deploying the Synapse Matrix Server using Docker, configuring essential settings, and enabling user registration.
Docker Compose Setup¶
- Docker Compose File:
version: '3.3'
services:
synapse:
container_name: synapse
image: matrixdotorg/synapse:latest
restart: always
ports:
- 8008:8008
volumes:
- ./data:/data
- Prepare the Data Directory:
-
Create a
data
directory alongside yourdocker-compose.yml
. This prevents Docker from setting it up as owned byroot
, which can complicate file permissions. -
Generate Matrix Configuration:
-
Run the following command to generate the Matrix configuration files. Replace
matrix.elzim.xyz
with your server name: -
Adjust Ownership of the Data Directory:
- Files in the
data
directory may be owned byroot
. Change the ownership to UID 991 with the following command: -
This ensures Synapse can access its configuration and data files.
-
Enable User Registration:
- Edit the
homeserver.yaml
file in thedata
directory: Let's incorporate the providedhomeserver.yaml
configuration details into the documentation for setting up Synapse Matrix Server using Docker. This includes steps for enabling user registration and configuring reCAPTCHA.
After generating the Synapse configuration files and adjusting file ownership, the next crucial step is to configure your Synapse server to allow user registration and enhance security with reCAPTCHA.
Editing homeserver.yaml
¶
Sample File¶
# Basic server information
server_name: "your.domain.com" # The domain name of your Matrix server.
pid_file: /data/homeserver.pid # Path to the PID file for the Synapse process.
# Networking
listeners:
- port: 8008
tls: false
type: http
x_forwarded: true # Enables handling of X-Forwarded-For headers.
resources:
- names: [client, federation]
compress: false
# Database settings
database:
name: sqlite3
args:
database: /data/homeserver.db # Path to the SQLite database file.
# Logging
log_config: "/data/your.domain.com.log.config" # Path to the logging configuration file.
# Media storage
media_store_path: /data/media_store # Where media files are stored on the disk.
# Registration and authentication
registration_shared_secret: "your_secret" # A secret used to authorize registration requests.
enable_registration: true # Allows users to register on your server.
enable_registration_captcha: true # Enables CAPTCHA for registrations.
# reCAPTCHA settings
recaptcha_public_key: "your_public_key"
recaptcha_private_key: "your_private_key"
recaptcha_siteverify_api: "https://www.google.com/recaptcha/api/siteverify"
# Privacy
report_stats: true # Whether to report anonymous statistics to the Matrix.org project.
# Security
macaroon_secret_key: "your_macaroon_secret"
form_secret: "your_form_secret"
signing_key_path: "/data/your.domain.com.signing.key" # Path to the server's signing key.
# Federation
trusted_key_servers:
- server_name: "matrix.org" # Trusted server for key validation.
Locate the homeserver.yaml
file within the data
directory you've created and make the following adjustments:
Basic Server Information¶
server_name
: This should be the domain name of your Matrix server. Replace"your.domain.com"
with your actual domain name.pid_file
: Specifies the path to the PID file for the Synapse process. It's set to/data/homeserver.pid
by default.
Networking¶
- The
listeners
configuration allows your server to handle HTTP connections on port8008
and properly manageX-Forwarded-For
headers if you're running Synapse behind a reverse proxy.
Database Settings¶
- Synapse uses SQLite by default for simplicity, indicated by the
"sqlite3"
name
. Thedatabase
argument points to the SQLite database file path.
Logging¶
log_config
: Path to the Synapse logging configuration file. Replace"your.domain.com.log.config"
with the appropriate path, ensuring it matches your domain.
Media Storage¶
media_store_path
: Defines where media files uploaded to the server are stored on disk.
Registration and Authentication¶
enable_registration
: Set totrue
to allow users to register on your server without an invitation.enable_registration_captcha
: Set totrue
and configure Google reCAPTCHA to prevent automated spam registrations.
reCAPTCHA Settings¶
recaptcha_public_key
andrecaptcha_private_key
: Obtain these from Google's reCAPTCHA admin console by creating a new site with reCAPTCHA v2 ("I'm not a robot" Checkbox). Include your server's domain in the list of authorized domains.recaptcha_siteverify_api
: The API URL used to verify the reCAPTCHA response.
Configuring Google reCAPTCHA¶
- Go to Google reCAPTCHA admin console to create a new site.
- Set the label and choose reCAPTCHA v2 with the "I'm not a robot" Checkbox.
- Add your server's domain to the list of authorized domains.
- Copy the site key and secret key into
homeserver.yaml
underrecaptcha_public_key
andrecaptcha_private_key
, respectively. - Ensure
enable_registration_captcha: true
is set in yourhomeserver.yaml
.
By following these steps, you've configured your Synapse server to allow user registrations while protecting against spam with Google reCAPTCHA. Continue with the deployment by running docker compose up -d
, and proceed to create a local admin account to start managing your Matrix server.
- Creating a Local Admin Account:
-
Use the following command to create an admin account. Replace
admin
andtesting123@!
with your desired username and password: -
Start Synapse Matrix Server:
- With the configuration complete, start your server:
- Ensure everything is running smoothly by accessing the server locally.
Making Your Server Public¶
For those looking to make their Synapse Matrix Server accessible publicly, setting up a Cloudflare Tunnel is a secure and effective method. Refer to this video tutorial for a step-by-step guide on deploying Cloudflare Tunnel.
Connecting with a Matrix Client¶
Once your server is up and running, you can connect using any Matrix-compatible client, such as Element, by pointing it to your server's URL.
By following these detailed steps, you'll have a fully functional Synapse Matrix Server ready for secure communication across your devices and with others on the Matrix network.