Set up a self-hosted Mastodon server on a €5 VPS

Evaluez cet article !
[Total: 0 Moyenne : 0]

Set up a self-hosted Mastodon server on a €5 VPS

Self-hosting Mastodon on a tight budget may seem risky, but with a €5 VPS, some optimizations, and a structured method, it becomes entirely possible to have a stable decentralized social network. This article explores each step, from prerequisites to secure production deployment, including Docker, SSL configuration, and daily maintenance.

In brief

🔑 On a **€5 VPS**, we favor **Ubuntu 22.04 LTS**, Docker, and a reverse proxy. This combination ensures **deployment simplicity** and **controlled cost**.

⚙️ The **installation** goes through Docker Compose: retrieving the Mastodon repository, editing the **.env** file, then launching the services. In 15 minutes, your container will have **PostgreSQL**, **Redis**, and the web service.

🔒 To guarantee **minimal security**, we use Let’s Encrypt (Certbot) behind a **Nginx reverse proxy**. Certificates are renewed automatically and HTTP traffic is redirected to HTTPS.

💾 **Scheduled backups** as PostgreSQL dumps and Docker volume archives protect your data. A cron script can send backups to remote storage.

1. Choose and prepare your VPS

1.1 €5 offers: selection criteria

Providers like Scaleway, OVHcloud, or Hetzner offer entry-level VPS at €5 per month, generally providing 1 vCPU, 2 GB RAM, and 20 GB SSD storage. Although these resources are limited, Mastodon remains functional if load is limited (number of users, frequency of background tasks). Before starting, check:

  • The type of storage (SSD vs HDD): an SSD significantly improves database I/O.
  • Bandwidth and burst policy.
  • Server location for latency relative to your target users.

1.2 Prepare Ubuntu 22.04 LTS

A stable and recent distribution guarantees security updates. After creating your instance:

  • Connect via SSH: ssh root@your-ip.
  • Update the system: apt update && apt upgrade -y.
  • Create a non-root user: adduser mastoadmin && usermod -aG sudo mastoadmin.
  • Install basic dependencies: apt install curl git ufw -y.
  • Enable the firewall: ufw allow OpenSSH && ufw enable.

2. Installing Mastodon with Docker

2.1 Install Docker and Docker Compose

Docker simplifies deployment by isolating services in containers. Run:

curl -fsSL https://get.docker.com | sh  
usermod -aG docker mastoadmin  
apt install docker-compose -y

Log out then log back in so the user joins the Docker group.

2.2 Clone the repository and configure the environment

Switch to mastoadmin and deploy Mastodon:

git clone https://github.com/mastodon/mastodon.git ~/mastodon  
cd ~/mastodon  
cp .env.production.sample .env.production

Open .env.production and adjust:

  • LOCAL_DOMAIN = your-domain.tld
  • DB_USER, DB_PASS, DB_NAME
  • REDIS_URL and STREAMING_CLUSTER
Mastodon Docker Architecture on VPS

2.3 Start the services

Build and start all containers:

docker-compose build  
docker-compose up -d

After a few moments, you should see:

Container Port Description
web 3000 Rails interface
streaming 4000 WebSocket
sidekiq Background tasks
postgres 5432 Database
redis 6379 Cache & queue

3. Advanced configuration and optimization

3.1 Set up SSL with Let’s Encrypt

TLS security is non-negotiable. Install Certbot and an Nginx reverse proxy:

apt install nginx certbot python3-certbot-nginx -y

Create a server block in /etc/nginx/sites-available/mastodon:

server {  
    listen 80; server_name your-domain.tld;  
    location / {  
        proxy_pass http://127.0.0.1:3000;  
        include proxy_params;  
    }  
}

Enable the site and generate the certificate:

ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/  
systemctl reload nginx  
certbot --nginx -d your-domain.tld --agree-tos --no-eff-email --redirect

3.2 Performance optimization

On a small VPS, every resource counts:

  • Limit Docker’s RAM: in /etc/docker/daemon.json, add "default-memory": "1G".
  • Configure sidekiq with a reduced number of threads (e.g. threads: 5).
  • Enable Rails assets production mode to reduce CPU load.

3.3 Backups and maintenance

Example backup script (daily cron):

#!/bin/bash  
TIMESTAMP=$(date +%F)  
docker exec mastodon_postgres pg_dumpall -U postgres > /var/backups/db_$TIMESTAMP.sql  
tar czf /var/backups/masto_data_$TIMESTAMP.tar.gz ~/mastodon/public/system

Send these files to remote storage (rsync, S3, Nextcloud) to avoid any loss.

FAQ

  • Do I need a more powerful VPS if the community grows?

    Yes, upgrade to 4 GB RAM and 2 vCPUs as soon as you notice significant load increases.

  • How to update Mastodon?

    In the ~/mastodon folder, run git pull, then docker-compose build and docker-compose up -d. Don’t forget to migrate the database if necessary.

  • Can I customize the interface?

    Edit the CSS/JS files in app/javascript and rebuild the Docker image. Beware of conflicts on official updates.

  • How to handle traffic spikes?

    Enable horizontal scaling of web and streaming containers by distributing load via a load balancer.

Evaluez cet article !
[Total: 0 Moyenne : 0]
Lire aussi  Searching for a word in Word: quick methods, advanced options, and pro tips
Julie - auteure Com-Strategie.fr

Julie – Auteure & Fondatrice

Étudiante en journalisme et passionnée de technologie, Julie partage ses découvertes autour de l’IA, du SEO et du marketing digital. Sa mission : rendre la veille technologique accessible et proposer des tutoriels pratiques pour le quotidien numérique.

Leave a comment