How to Set Up a Single-User Mastodon Instance With Cheap VPS
🔍 WiseChecker

How to Set Up a Single-User Mastodon Instance With Cheap VPS

Running your own Mastodon instance gives you full control over your social media presence and data. For a single user, a cheap VPS from providers like DigitalOcean, Linode, or Vultr is sufficient to host a functional instance. The key constraint is that Mastodon requires at least 2 GB of RAM and a dedicated domain name. This article walks through provisioning a VPS, installing Mastodon with Docker, and configuring the instance for one person.

Key Takeaways: Single-User Mastodon on a Budget VPS

  • VPS with 2 GB RAM and 2 vCPUs: Minimum hardware to run Mastodon without swapping or crashes.
  • Docker Compose deployment: Simplifies installation and updates through pre-built containers.
  • Cloudflare DNS and SSL proxy: Provides free TLS termination and DDoS protection for the instance.

ADVERTISEMENT

What Mastodon Requires for a Single-User Instance

Mastodon is a Rails application that uses PostgreSQL for data storage and Redis for background job queues. Even with one user, the application server, database server, and background workers all run concurrently. The official documentation recommends 2 GB of RAM as the absolute minimum for a production instance. A single-user instance with light usage can run on a $6 to $12 per month VPS if you choose a provider that offers 2 GB RAM at that price tier.

Storage requirements are modest. The database and media files for one active user rarely exceed 10 GB in the first year. You can start with a 25 GB disk and expand later. The domain name must be a registered domain where you can set DNS records. A subdomain like social.example.com is common.

Software Dependencies

The Mastodon stack includes:

  • Ruby on Rails (application server)
  • PostgreSQL 12 or later (database)
  • Redis 6 or later (caching and queues)
  • Node.js 16+ (asset compilation)
  • Nginx or Caddy (reverse proxy)

Installing these manually on a cheap VPS is possible but error-prone. The Docker Compose method packages all dependencies into containers, which reduces configuration mistakes and simplifies updates.

Step-by-Step Instructions to Deploy Mastodon With Docker on a VPS

Step 1: Provision the VPS and Configure SSH Access

  1. Create a VPS with 2 GB RAM and Ubuntu 22.04
    Log into your VPS provider dashboard. Select the smallest plan that offers 2 GB RAM and at least 25 GB SSD storage. Choose Ubuntu 22.04 LTS as the operating system. Note the public IP address after creation.
  2. Connect via SSH and update packages
    Open a terminal. Run ssh root@your-vps-ip. After connecting, run apt update && apt upgrade -y to install all available security patches.
  3. Set the hostname to your domain
    Run hostnamectl set-hostname social.example.com and replace the domain with your own. Edit /etc/hosts to add a line: 127.0.0.1 social.example.com.

Step 2: Install Docker and Docker Compose

  1. Install Docker from the official repository
    Run the following commands in sequence:
    apt install -y ca-certificates curl gnupg lsb-release
    mkdir -p /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
    apt update
    apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
  2. Verify the installation
    Run docker --version and docker compose version. Both commands should return version numbers without errors.

Step 3: Download Mastodon and Configure Environment Variables

  1. Clone the Mastodon repository
    Run git clone https://github.com/mastodon/mastodon.git then cd mastodon.
  2. Copy the example environment file
    Run cp .env.production.sample .env.production.
  3. Generate a secret key and OTP secrets
    Run openssl rand -hex 64 and copy the output. Open .env.production with a text editor. Set SECRET_KEY_BASE to that value. Run openssl rand -hex 64 again and set OTP_SECRET. Run head -c 64 /dev/urandom | base64 and set VAPID_PRIVATE_KEY. Then run openssl ecparam -name prime256v1 -genkey -noout -out /dev/stdout | base64 | tr -d '\n' and set VAPID_PUBLIC_KEY.
  4. Set the domain and database credentials
    In the same file, edit these lines:
    LOCAL_DOMAIN=social.example.com
    DB_HOST=db
    DB_USER=postgres
    DB_NAME=postgres
    DB_PASS=
    REDIS_HOST=redis
    Leave DB_PASS empty for now. The Docker Compose file uses the default PostgreSQL user without a password.

Step 4: Configure Nginx and SSL With Cloudflare

  1. Set up DNS in Cloudflare
    In your Cloudflare dashboard, add an A record for social pointing to your VPS IP address. Enable the orange cloud (proxy) icon to activate Cloudflare SSL.
  2. Create an Nginx configuration file
    On the VPS, create /etc/nginx/sites-available/mastodon with the following content:
    server {
        listen 80;
        server_name social.example.com;
        return 301 https://$server_name$request_uri;
    }
    
    server {
        listen 443 ssl http2;
        server_name social.example.com;
    
        ssl_certificate /etc/ssl/certs/cloudflare.crt;
        ssl_certificate_key /etc/ssl/private/cloudflare.key;
    
        location / {
            proxy_pass http://127.0.0.1:3000;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    
        location /api/v1/streaming {
            proxy_pass http://127.0.0.1:4000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
  3. Enable the site and restart Nginx
    Run ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/. Then run systemctl restart nginx.
  4. Upload your Cloudflare origin certificate
    In Cloudflare, go to SSL/TLS > Origin Server. Create an origin certificate that covers your domain and all subdomains. Copy the certificate and key content into the files referenced in the Nginx config above.

Step 5: Build and Start Mastodon Containers

  1. Build the Docker images
    From the mastodon directory, run docker compose build. This step compiles assets and may take 10 to 15 minutes on a cheap VPS.
  2. Run database migrations
    Run docker compose run --rm web rails db:migrate. This creates the database tables.
  3. Create the admin account
    Run docker compose run --rm web rails db:seed. This creates a default admin user with email admin@example.com and password mastodonadmin. Change these immediately after first login.
  4. Start all services
    Run docker compose up -d. This starts the web, streaming, sidekiq, and database containers in detached mode.

ADVERTISEMENT

Common Issues After Deployment

VPS Runs Out of Memory During Build

If the build process fails with a killed process or OOM error, your VPS likely has less than 2 GB of RAM. Add a 2 GB swap file: fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile. Add /swapfile none swap sw 0 0 to /etc/fstab to make it permanent.

Cannot Send Emails for Account Confirmation

Mastodon requires an SMTP server to send confirmation emails. For a single-user instance, you can use a free SendGrid account (100 emails per day) or a Mailgun trial. Add these variables to .env.production: SMTP_SERVER=smtp.sendgrid.net, SMTP_PORT=587, SMTP_LOGIN=apikey, SMTP_PASSWORD=your-sendgrid-api-key, SMTP_FROM_ADDRESS=noreply@social.example.com. Then restart containers with docker compose restart.

Mastodon Web Interface Returns 502 Bad Gateway

This usually means Nginx cannot reach the Docker containers. Verify the containers are running with docker ps. Check that the web container exposes port 3000 and the streaming container exposes port 4000. Also confirm that LOCAL_DOMAIN in .env.production matches the server_name in the Nginx config.

Single-User Mastodon vs Mastodon Hosted Plan

Item Self-Hosted Single-User Instance Mastodon Hosted Plan (Mastodon.social)
Monthly cost $6 to $12 (VPS) plus domain ($1-2) Free for basic account
Control Full admin access, custom moderation rules No server-level settings
Maintenance Manual updates, security patching Automatic updates by host
Data ownership All data on your VPS Data stored on host servers
Scalability Limited by VPS resources Handles many users

After the containers are running, open https://social.example.com in a browser. Log in with the admin account created during setup. Go to Preferences > Administration > Server Settings to customize the instance name, description, and contact email. For a single-user instance, disable open registration in Preferences > Administration > Server Settings > Registrations to prevent others from joining. Consider setting up automatic weekly backups of the PostgreSQL database using docker compose exec db pg_dump -U postgres > backup.sql and storing the file off-server via rsync or a cloud storage bucket.

ADVERTISEMENT