How to Install Matrix Synapse on Ubuntu 20.04

/ Category: Tutorials, Ubuntu / Comments: None

How to Install Matrix Synapse on Ubuntu 20.04
Spread the love

In this tutorial, we are going to show you how to install Matrix Synapse on Ubuntu 20.04 OS.

Matrix Synapse is an open-source chat application written in Python, used for real-time communication for VOIP services and instant messaging. Synapse is developed to implement the matrix for decentralized communication which can store personal data from the chat history, user data and etc. In this tutorial, we will install Matrix Synapse with Apache as a reverse proxy.

The installation is very easy and can take up to 30 minutes. Let’s get started!

Prerequisites

  • A server with Ubuntu 20.04 as OS
  • User privileges: root or non-root user with sudo privileges
  • A valid domain pointed to your server IP address

</ul

Step 1. Update the System

We need to update the system packages to be updated to the latest versions available.

sudo apt-get update -y && sudo apt-get upgrade -y

Step 2. Install Apache Web Server

Install the Apache Web server with the following command:

sudo apt install apache2

Once, installed start and enable the service.

sudo systemctl enable apache2 && sudo systemctl start apache2

Check if the service is up and running:

sudo systemctl status apache2

You should receive the following output:

[email protected]:~# sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-05-07 12:08:39 UTC; 51min ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 662 (apache2)
      Tasks: 7 (limit: 4617)
     Memory: 24.1M
     CGroup: /system.slice/apache2.service
             ├─  662 /usr/sbin/apache2 -k start
             ├─  846 /usr/sbin/apache2 -k start
             ├─  847 /usr/sbin/apache2 -k start
             ├─  848 /usr/sbin/apache2 -k start
             ├─  849 /usr/sbin/apache2 -k start
             ├─  851 /usr/sbin/apache2 -k start
             └─22759 /usr/sbin/apache2 -k start

May 07 18:08:37 host.test.vps systemd[1]: Starting The Apache HTTP Server...

Step 3. Install Matrix Synapse

Before we can install Matrix synapse, we need to add the GPG key and repository since it is not added by default on Ubuntu 20.04

wget -qO /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg

Add the repository:

echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/matrix-org.list

Update the repository and install Matrix Synapse:

sudo apt-get update -y

apt-get install matrix-synapse-py3 -y

On the first window enter your domain name:

On the second screen select Yes and hit the Enter on your keyboard for the installation to start.

Once, the installation is finished, enable and start the matrix synapse service:

sudo systemctl start matrix-synapse && sudo systemctl enable matrix-synapse

To check the status of the Matrix Synapse service execute the following command:

sudo systemctl status matrix-synapse

You should receive the following output:

[email protected]:~# sudo systemctl status matrix-synapse
● matrix-synapse.service - Synapse Matrix homeserver
     Loaded: loaded (/lib/systemd/system/matrix-synapse.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-05-08 17:15:57 UTC; 12min ago
   Main PID: 36817 (python)
      Tasks: 8 (limit: 4617)
     Memory: 80.1M
     CGroup: /system.slice/matrix-synapse.service
             └─36817 /opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse>

May 08 17:15:46 host.test.vps systemd[1]: Starting Synapse Matrix homeserver..

Step 4. Configure Matrix Synapse

We are going to create a secret password and store in the default matrix synapse configuration at /etc/matrix-synapse/homeserver.yaml. Open the file and paste the following lines of code under the resources section:

resources:
- names: [client, federation]
compress: false

enable_registration: false
registration_shared_secret: "<strong>YourStrongSecretPasswordWithNumbersAndDigits</strong>"

Once, you save the changes, close the file and restart the matrix synapse service.

sudo systemctl restart matrix-synapse

Step 5. Create Apache Virtual Host File and Reverse Proxy

Create the file:

touch /etc/apache2/sites-available/matrix.conf

Open the file and paste the following lines of code:

<VirtualHost *:80>
    ServerName yourdomain.com
    <Location />
      ProxyPass http://0.0.0.0:8008/_matrix/static/
      ProxyPassReverse http://0.0.0.0:8008/_matrix/static/
  </Location>
    RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
    AllowEncodedSlashes NoDecode
    ProxyPreserveHost on
    ProxyPass /_matrix http://0.0.0.0:8008/_matrix nocanon
    ProxyPassReverse /_matrix http://0.0.0.0:8008/_matrix
    ProxyPass /_synapse/client http://0.0.0.0:8008/_synapse/client nocanon
    ProxyPassReverse /_synapse/client http://0.0.0.0:8008/_synapse/client
</VirtualHost>

Enable the website and some apache modules:

a2ensite matrix.conf
a2enmod proxy
a2enmod proxy_http

Check the Apache Configuration with command below:

apachectl -t

You should receive the following output:

[email protected]:~# apachectl -t
Syntax OK

If the syntax is OK, restart the apache service:

sudo systemctl restart apache2

Now, you can access the Matrix Synapse at http://yourdomain.com and see the following screen.

Congratulations! You successfully installed and configured Matrix Synapse on Ubuntu 20.04 in no time. Of course, if you find any difficulties while installing or configuring this software you can always contact our epic support. We are available 24/7 and will make your server to running smoothly with any application you want.

If you liked this post on how to install Matrix Synapse on Ubuntu 20.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Be the first to write a comment.

Your feedback