How to run Synapse

2020-02-25

tags: chat, services

Synapse is an implementation of the matrix homeserver that's created by matrix team and written in Python/Twisted. With this software, we can implement the matrix way for decentralized communication, we can create our own home server and store all user personal info, chat history, create the room for own use, etc. Matrix is a new ecosystem for decentralized communication in real time for open federated instant messaging and VoIP services. It provides RESTful HTTP JSON APIs for building distributed and federated chat servers with no single point of control and failure and provides all references for the APIs.

Install Synapse and NGINX.

Edit the nginx.conf and add inside the http tag:

http {

    # ...

    include conf.d/synapse.conf

    # ...

    server {

        # ...

    }

}

Create the conf.d directory inside NGINX.

Create a synapse.conf file inside the conf.d directory you created. It should contain this:

ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;

server {
    listen 443 ssl;
    server_name matrix.your_domain.com;

    location / {
        proxy_pass http://127.0.0.1:8008;
    }

}

server {
    listen 8448 ssl;
    server_name your_domain.com;

    location / {
        proxy_pass http://127.0.0.1:8008;
    }

}

Move to the Synapse directory.

# cd /var/lib/synapse

Generate a configuration file for Synapse before you start the service.

# sudo -u synapse python -m synapse.app.homeserver --server-name your_domain.com --config-path /path/to/synapse/homeserver.yaml --generate-config --report-stats=yes

Warning: Synapse can be very memory hungry if you join large rooms from other federations. A nasty but good solution is to enable complexity checking in homeserver.yaml

This option will not enable you to join large rooms. If you think it's a bad solution then buy some RAM.

limit_remote_rooms:
    enabled: true

Start the Synapse service.

Register a new Matrix user in your server using the register_new_matrix_user.py script which comes with the Synapse package you installed. Usually gets installed in the /bin directory too.

# register_new_matrix_user -c /etc/synapse/homeserver.yaml

Start the NGINX service.

If everything went well, we can test our server via 2 different ways.

By checking https://matrix.your_domain.com or by entering your_domain.com in https://federationtester.matrix.org.

You can also check NGINX error.log and Synapse homeserver.log for more information.

Happy chatting!