How to Self-Host Matrix (Synapse) on a VPS (Complete Guide)
Self-hosting Matrix Synapse on a VPS can seem daunting, but with this detailed guide, you’ll have your own matrix communication setup in no time. This guide covers the essential steps to install and configure Synapse using a VPS, focusing on ease of understanding for developers and homelab enthusiasts.
What You Need
Before you start, ensure you have:
- A VPS (choose based on your budget and performance needs)
- A domain name (optional but recommended for easier access)
- Basic knowledge of terminal commands and configurations
Recommended VPS Options
| VPS Provider | Price (per month) | Features | Link |
|---|---|---|---|
| Contabo VPS | 5.99 EUR | 8 GB RAM, 200 GB SSD | Contabo |
| Hetzner Cloud | 4.15 EUR | 2 GB RAM, 20 GB SSD | Hetzner |
| DigitalOcean | 6 USD | 1 GB RAM, 25 GB SSD | DigitalOcean |
| Vultr | 6 USD | 1 GB RAM, 25 GB SSD | Vultr |
| Linode | 5 USD | 1 GB RAM, 25 GB SSD | Linode |
For a more comprehensive comparison, check the full VPS comparison.
Step 1: Set Up Your VPS
-
Create an account with your chosen VPS provider.
-
Deploy a new VPS instance. For Matrix Synapse, a server with at least 2 GB RAM is recommended.
-
Access your VPS via SSH:
ssh root@your-vps-ip -
Update your system:
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
Install the required packages to run Matrix Synapse:
sudo apt install python3-pip python3-dev libjpeg-dev libssl-dev libpq-dev postgresql postgresql-contrib -y
Step 3: Install Matrix Synapse
-
Install Synapse using pip:
sudo pip3 install matrix-synapse -
Create a configuration file:
sudo synapse_homeserver_setupFollow the prompts to configure your homeserver, inputting your domain, server name, and other relevant info.
-
Create a systemd service file: Create a file at
/etc/systemd/system/matrix-synapse.service:[Unit] Description=Matrix Synapse server After=postgresql.service [Service] ExecStart=/usr/local/bin/synapse_homeserver User=@your_username Group=@your_group [Install] WantedBy=multi-user.target -
Start and enable the service:
sudo systemctl start matrix-synapse sudo systemctl enable matrix-synapse
Step 4: Configure Your Domain and SSL
-
Point your domain to your VPS: Update the DNS settings for your domain to point to the VPS IP.
-
Install Certbot for SSL:
sudo apt install certbot python3-certbot-nginx -y -
Generate SSL certificates:
sudo certbot certonly --standalone -d yourdomain.com -
Configure Nginx: Create a file in
/etc/nginx/sites-available/matrixand link it in/etc/nginx/sites-enabled/with the following content:server { listen 443 ssl; server_name yourdomain.com; ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; location / { proxy_pass http://localhost:8008; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } -
Test Nginx and Restart:
sudo nginx -t sudo systemctl restart nginx
Step 5: Access Your Matrix Synapse Server
Once your server is running and Nginx is set up, you can access your Matrix Synapse at https://yourdomain.com.
FAQs
1. What are the system requirements for running Matrix Synapse?
To run Matrix Synapse effectively, it is recommended that your VPS has at least 2 GB of RAM, a reliable CPU, and an adequate storage solution, such as SSD. This allows the server to handle multiple connections and operations required for a smooth user experience. A basic installation can run on lower specs, but performance may degrade as usage increases, particularly under higher loads with many simultaneous users.
2. How do I back up my Matrix Synapse data?
Backing up your Matrix Synapse installation involves primarily backing up the PostgreSQL database, along with the homeserver configuration. You can create regular backups of your database with commands like pg_dump. Additionally, ensure that configurations under /etc/matrix-synapse/ are saved. Setting up cron jobs for automated backups is also advisable.
3. Can I run Matrix in a Docker container on a VPS?
Yes, running Matrix Synapse in a Docker container is a popular option for deployment. Docker allows for easier management and scaling of your application. You can find official images and detailed instructions in the Matrix Synapse Docker documentation. The process involves pulling the image, setting up environment variables to configure the homeserver, and running containers with persistent storage for data continuity.
By following the steps outlined in this guide, you can confidently self-host Matrix Synapse on your chosen VPS, effectively managing your communication needs. Enjoy your newly configured Matrix server!