Self-hosted Matrix homeserver with Matrix Authentication Service (MAS), Element Web, Element Call, Synapse Admin console, and LiveKit video calling.
Features:
- ✅ Element X mobile client support via MAS (Matrix Authentication Service)
- ✅ Web-based admin console for server management
- ✅ Audio/Video calls from Element X mobile clients via LiveKit
- ✅ Modern OIDC/OAuth2 authentication
- ✅ Full federation support
- Docker and Docker Compose installed
- SSL certificates (Let's Encrypt recommended)
- Domain name pointing to your server
- Ports 80, 443, 8448 (Matrix federation), 7880-7881, 3478, 5349, 50000-50200 open
Run the comprehensive initialization script:
chmod +x init.sh
./init.shThis automated script will:
- ✓ Check all prerequisites (Docker, Docker Compose, OpenSSL, envsubst)
- ✓ Create
.envfile with all required secrets auto-generated - ✓ Prompt for your domain name and server IP
- ✓ Generate all configuration files from templates (including MAS)
- ✓ Generate Synapse signing key automatically
- ✓ Generate MAS secrets for Element X authentication
- ✓ Validate SSL certificates (if present)
- ✓ Prepare Docker volumes with correct permissions
- ✓ Provide next steps summary
That's it! The script handles everything needed for production deployment, including MAS setup for Element X mobile clients.
sudo apt-get install certbot
sudo certbot certonly --standalone -d your-domain.comdocker-compose up -dOpen your browser and navigate to:
https://your-domain.com/admin
Login with your admin credentials to manage your Matrix server.
Element X mobile clients can connect using your server domain. The MAS integration handles authentication automatically via OIDC.
Download Element X:
- iOS: App Store
- Android: Google Play
Setup:
- Open Element X
- Select "Use other homeserver"
- Enter your server domain:
your-domain.com - Register or login - MAS handles authentication
- Audio/Video calls work automatically via LiveKit
If you prefer manual configuration:
cp .env.example .env
# Edit .env and set your values./setup.shThis will generate configuration files from templates.
docker run --rm -v $PWD/synapse:/config \
matrixdotorg/synapse:latest generate_signing_key \
-o /config/matrix.signing.keydocker-compose up -d.
├── init.sh # 🆕 One-command initialization script
├── setup.sh # Interactive configuration generator
├── docker-compose.yml # Service definitions
├── .env.example # 🆕 Example environment variables
├── .env # Generated secrets (not in git)
│
├── synapse/ # Matrix Synapse homeserver
│ ├── homeserver.yaml.template # Synapse config template
│ ├── docker-entrypoint.sh # Synapse startup script
│ ├── log.config # Logging configuration
│ └── matrix.signing.key # Generated signing key (not in git)
│
├── element-web/ # Element Web UI
│ ├── config.json.template # Element Web config template
│ └── config.json # Generated config (not in git)
│
├── element-call/ # Element Call (Video/Voice)
│ ├── config.json.template # Element Call config template
│ └── config.json # Generated config (not in git)
│
├── mas/ # Matrix Authentication Service
│ ├── config.yaml.template # MAS config template
│ └── docker-entrypoint.sh # MAS startup script (processes template)
│
├── nginx/ # Reverse proxy & SSL termination
│ ├── nginx.conf # Main nginx config
│ ├── matrix.conf.template # Matrix routes template
│ └── docker-entrypoint.sh # Nginx startup script
│
└── livekit/ # LiveKit SFU (WebRTC)
└── livekit.yaml # LiveKit config (uses env vars)
All secrets and environment-specific settings are stored in .env file (not committed to git).
| Variable | Description | Example |
|---|---|---|
SYNAPSE_SERVER_NAME |
Your Matrix server domain | matrix.example.com |
SSL_CERT_DOMAIN |
SSL certificate domain | matrix.example.com |
NODE_IP |
External IP for WebRTC | 1.2.3.4 |
ADMIN_EMAIL |
Administrator email | admin@example.com |
REGISTRATION_SHARED_SECRET |
Synapse registration secret | Auto-generated |
MACAROON_SECRET_KEY |
Synapse auth token secret | Auto-generated |
FORM_SECRET |
Synapse form security secret | Auto-generated |
APIKey |
LiveKit API key | Auto-generated |
LIVEKIT_SECRET |
LiveKit API secret | Auto-generated |
MAS_ENCRYPTION_SECRET |
MAS database encryption | Auto-generated |
MAS_SIGNING_KEY |
MAS JWT signing key | Auto-generated |
MAS_SYNAPSE_SECRET |
MAS-Synapse shared secret | Auto-generated |
MAS_ADMIN_TOKEN |
MAS admin token | Auto-generated |
All secrets are automatically generated by init.sh using cryptographically secure random values.
The deployment includes eight Docker containers:
- synapse - Matrix homeserver (core messaging)
- mas - Matrix Authentication Service (OIDC/OAuth2 for Element X)
- synapse-admin - Web-based admin console
- element-web - Web UI for Matrix
- element-call - Standalone video calling app
- livekit - WebRTC SFU for video/audio
- lk-jwt-service - JWT token issuer for LiveKit
- nginx - Reverse proxy and TLS termination
| Port | Protocol | Service | Purpose |
|---|---|---|---|
| 80 | TCP | nginx | HTTP (redirects to HTTPS) |
| 443 | TCP | nginx | HTTPS (main access) |
| 8448 | TCP | nginx | Matrix federation |
| 7880 | TCP | livekit | WebSocket |
| 7881 | TCP | livekit | RTC |
| 3478 | UDP | livekit | TURN (UDP) |
| 5349 | TCP | livekit | TURN (TLS) |
| 50000-50200 | UDP | livekit | RTP (media streams) |
To update configuration:
- Edit
.envfile with new values - Run
./init.shto regenerate configs (will preserve existing .env values) - Restart services:
docker-compose restart
Or manually edit .template files and run ./setup.sh.
docker-compose ps
docker-compose logs -fdocker-compose restart synapsedocker-compose logs -f synapsecurl https://federationtester.matrix.org/api/report?server_name=your-domain.com- Never commit
.envfile to version control - Keep SSL certificates updated (Let's Encrypt auto-renewal recommended)
- Regularly update Docker images:
docker-compose pull && docker-compose up -d - Monitor Synapse logs for suspicious activity
- Consider enabling rate limiting in Synapse config
MIT