Here we will discuss the easiest way to install a chat platform for personal use cases with Docker Compose on a Linux server. We are not going into detail as I'm assuming the reader is familiar with Linux, Docker, NGINX, and some basic networking terms. But let me know if you think I should update this doc in advance. This doc is the minimal and most straightforward approach that I could get to set up a private chat server with reliable VoIP and Video features. On the other hand, "Synapse Matrix" and "Element" are super powerful and customizable; peek at the official documentation.
- https://matrix.org/docs/projects/server/synapse
- https://element.io/solutions/on-premise-collaboration
- This setup is powered by SQLITE which is not production level database server consider using PostgreSQL instead.
- This setup is allowing user registration without any verification, but its easy to config a central authentication with LDAP server.
- A Linux server with a Public IP
- Installed NGINX (we are not containerizing the NGINX installation)
- Two DNS records pointing to this server
- m.example.com -> for the synapse matrix and admin WebUI
- e.example.com -> for element WebUI
- Installed docker + docker compose
- Valid SSL certificates for the named DNS records
-
Clone this repo or copy its contents to a directory and drive it into
mkdir $HOME/matrix cd $HOME/matrix
-
Create A or AAA DNS Records pointing to the Server Public IP
- m.example.com -> for the synapse matrix and admin WebUI
- e.example.com -> for element WebUI
-
Configure NGINX with the sample config
matrix.config
file, which can be found here- Replace example.com
- Copy your SSL Certificates in the given path or use Certbot to generate certs
-
Restart NGINX
sudo service nginx restart
-
Create a docker network for the matrix network (assuming this server is used by other services)
sudo docker network create --driver=bridge --subnet=10.10.10.0/24 --gateway=10.10.10.1 matrix_net
-
Create Element config and Copy and paste example contents into your file.
nano element-config.json or curl https://develop.element.io/config.json --output element-config.json
-
Remove
"default_server_name": "matrix.org"
fromelement-config.json
as this is deprecatedsed -i '/"default_server_name": "matrix.org"/d' element-config.json
-
Add our custom homeserver to the top of
element-config.json
(Replace the Domain Name example.com)"default_server_config": { "m.homeserver": { "base_url": "https://m.example.com", "server_name": "m.example.com" }, "m.identity_server": { "base_url": "https://vector.im" } },
-
Generate Synapse config (homeserver.yaml) with this command (Replace the Domain Name example.com)
sudo docker run -it --rm \ -v "$HOME/matrix/synapse:/data" \ -e SYNAPSE_SERVER_NAME=m.example.com \ -e SYNAPSE_REPORT_STATS=yes \ matrixdotorg/synapse:latest generate
-
As its common that your client are behind NATed network traffic you may need to add TRUN service to your setup for reliable VoIP connections.
Note: This is required only for mobile devices (iOS and Android), The Element Web UI is using WebRTC which enables port punching though NAT network without TRUN.
Update thecoturn\turnserver.config
file:- Update the password
SOMESECURETEXT
- Add the Server Public IP at the last line
- replace the
example.com
- Update the password
-
Add Coturn configs to the
homeserver.yml
Replace the configs form the previous stepturn_uris: - "turn:m.example.com:3478?transport=udp" - "turn:m.example.com:3478?transport=tcp" - "turns:m.example.com:3478?transport=udp" - "turns:m.example.com:3478?transport=tcp" turn_shared_secret: "SOMESECURETEXT" turn_user_lifetime: 1h turn_allow_guests: true
-
deploy the docker compose
sudo docker-compose up -d
-
Create an Admin User
- Access docker shell
sudo docker compose exec -it synapse bash
- run command
register_new_matrix_user -c /data/homeserver.yaml http://localhost:8008
- Follow the on screen prompts
- Enter exit to leave the container's shell with
exit
- Access docker shell
-
If you need to allow users to register without any verification and the following line to
homeserver.yml
and restart the synapse containerenable_registration: true enable_registration_without_verification: true
-
Check you configuration:
- Element UI: https://e.example.com/_matrix
- Matrix Core Endpoint: https://m.example.com/_matrix
- Admin WebUI: https://m.example.com
-
Thats it, all done. you can create users with the admin web ui and download the client App from:
- https://github.com/coturn/coturn
- https://matrix-org.github.io/synapse/v1.37/turn-howto.html
- https://github.com/Miouyouyou/matrix-coturn-docker-setup/blob/master/docker-compose.1.yml
- https://github.com/coturn/coturn/blob/master/docker/docker-compose-all.yml
- https://github.com/spantaleev/matrix-docker-ansible-deploy/tree/master/docs
- https://blog.bartab.fr/install-a-self-hosted-matrix-server-part-3/
- https://github.com/vector-im/element-web/blob/develop/docs/config.md
- https://matrix-org.github.io/synapse/latest/usage/administration/admin_faq.html
- https://cyberhost.uk/element-matrix-setup/