Personal Matrix stack running:
- Synapse (homeserver)
- Postgres (Synapse DB)
- Element Web (client UI)
- Synapse Admin (admin UI)
- Nginx (TLS + reverse proxy)
- Docker + Docker Compose v2 (
docker compose) - Two DNS records pointing to this host:
${MATRIX_DOMAIN}(your homeserver domain)${ELEMENT_WEB_DOMAIN}(your Element Web domain)${SYNAPSE_ADMIN_DOMAIN}(your admin UI domain)
- A TLS certificate that covers both domains (SAN cert), or a wildcard cert. You can use Let's Encrypt or any other CA.
- An Htpasswd file for basic auth on the admin UI.
- Create
.envfrom the example:
cp .env.example .envSet at least:
MATRIX_DOMAINSYNAPSE_ADMIN_DOMAINPOSTGRES_PASSWORDTLS_CERT_FILE,TLS_KEY_FILE,HTPASSWD_FILE(paths on the host)
By default the example expects:
nginx/.keys/fullchain.pemnginx/.keys/privkey.pemnginx/.keys/htpasswd
Alternatively to static certs, you can use Let's Encrypt with Certbot or similar tools to generate certs.
- Update Nginx domains in nginx/nginx.conf:
- Replace
example.comwith yourMATRIX_DOMAIN - Replace
element.example.comwith yourELEMENT_WEB_DOMAIN - Replace
matrix-admin.example.comwith yourSYNAPSE_ADMIN_DOMAIN
- Update Element config in element/config.json:
- Replace
example.comwith yourMATRIX_DOMAIN
Generate an Htpasswd file for basic auth on the Synapse Admin UI.
sudo apt update && sudo apt install apache2-utils -y
htpasswd -c nginx/.keys/htpasswd adminuser
chmod 600 nginx/.keys/htpasswdPlace your cert/key where TLS_CERT_FILE / TLS_KEY_FILE point.
cp /path/to/fullchain.pem nginx/.keys/fullchain.pem
cp /path/to/privkey.pem nginx/.keys/privkey.pem
chmod 600 nginx/.keys/privkey.pemPre-generate the Synapse config:
docker compose run --rm synapse generateThis creates synapse/data/homeserver.yaml. Since we are using Postgres, edit the database section like so:
database:
name: psycopg2
args:
user: synapse
password: <pass> # use the value from your .env POSTGRES_PASSWORD
dbname: synapse
host: postgres
cp_min: 5
cp_max: 10Next, edit any other Synapse settings you want in synapse/data/homeserver.yaml.
Read the Synapse docs for more info: https://element-hq.github.io/synapse/latest/welcome_and_overview.html
Bring the stack up:
docker compose up -dNavigate to project root and run the registration helper:
docker compose exec synapse register_new_matrix_user -c /data/homeserver.yaml -a http://localhost:8008Follow the prompts to create your first admin user.
Login with your newly created user at the URLs you set up in your env and nginx config: Should be something like:
- Element Web:
https://element.example.com/ - Synapse Admin UI:
https://matrix-admin.example.com/
You may download any Matrix client (Element, FluffyChat, etc.) and connect to your homeserver from any device at https://$MATRIX_DOMAIN/.
List of clients: https://matrix.org/ecosystem/clients/
Your Matrix ID (MXID) will be in the format: @username:$MATRIX_DOMAIN
- Element:
https://$ELEMENT_WEB_DOMAIN/ - Synapse Client-Server API:
https://$MATRIX_DOMAIN/_matrix/... - Federation:
https://$MATRIX_DOMAIN:8448/ - Synapse Admin UI:
https://$SYNAPSE_ADMIN_DOMAIN/
docker compose logs -f --tail=200
docker compose downReach out on Matrix: @ayman:alsuleihi.com
Feel free to open issues or submit pull requests.
MIT License. See LICENSE file for details.