Independent testing Updated April 2026 387 self-hosting guides 5 VPS providers tested

guide

How to Self-Host Mastodon on a VPS (Complete Guide)

Learn how to self-host Mastodon on a VPS with a step-by-step 2026 guide covering install, configuration, and securing Mastodon for reliable daily use.

Introduction

Mastodon is a popular open-source microblogging platform that allows users to create their own social networks. Self-hosting Mastodon gives you full control over your data and the ability to customize your instance. In this guide, we will walk you through the steps to install Mastodon on a VPS, covering everything from server selection to configuration.

Prerequisites

Before we start, ensure you have the following:

Choosing a VPS Provider

When selecting a VPS provider, consider the following:

ProviderStarting PriceSpecs
Contabo VPS5.99 EUR/mo4 vCPU, 8 GB RAM, 300 GB SSD
Hetzner Cloud4.15 EUR/mo2 vCPU, 2 GB RAM, 20 GB SSD
DigitalOcean6 USD/mo1 vCPU, 1 GB RAM, 25 GB SSD
Vultr6 USD/mo1 vCPU, 1 GB RAM, 25 GB SSD
Linode5 USD/mo1 vCPU, 1 GB RAM, 25 GB SSD

For this guide, we recommend either Contabo or Hetzner Cloud for their balance of price and performance.

Step 1: Initial Setup

  1. Create a new VPS instance: Choose your desired provider and set up a new instance with a minimal installation of Ubuntu.

  2. Update your system: Connect to your VPS using SSH and run the following commands:

    sudo apt update
    sudo apt upgrade -y
  3. Install required packages:

    sudo apt install -y git curl wget build-essential

Step 2: Install Docker and Docker Compose

Mastodon runs within Docker containers, which makes installation and management easier.

  1. Install Docker:

    curl -fsSL https://get.docker.com -o get-docker.sh
    sh get-docker.sh
  2. Install Docker Compose:

    sudo apt install -y python3-pip
    sudo pip3 install docker-compose

Step 3: Clone Mastodon Repository

Next, clone the Mastodon repository and navigate into it.

git clone https://github.com/mastodon/mastodon.git ~/.mastodon
cd ~/.mastodon

Step 4: Configure Environment Variables

Create a new configuration file and populate it with your details:

cp .env.production.sample .env.production
nano .env.production

Make sure to set your domain, email, and other relevant configurations.

Step 5: Install Dependencies

In order to build the Mastodon app, you need to install Node.js, Yarn, and other dependencies.

  1. Install Node.js:

    curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt install -y nodejs
  2. Install Yarn:

    npm install --global yarn
  3. Install Ruby dependencies:

    sudo apt install -y gcc libpq-dev libjpeg-dev libxml2-dev libxslt1-dev
  4. Install Bundler:

    sudo gem install bundler
  5. Install gems:

    bundle install

Step 6: Database Setup

Mastodon uses PostgreSQL. Create a new database for your instance.

  1. Install PostgreSQL:

    sudo apt install -y postgresql postgresql-contrib
  2. Create a database user and database:

sudo -u postgres createuser mastodon
sudo -u postgres createdb mastodon_production --owner mastodon
  1. Assign a password:

    Open the PostgreSQL prompt:

    sudo -u postgres psql

    Then run the following commands, substituting <yourpassword>:

    ALTER USER mastodon PASSWORD '<yourpassword>';

Step 7: Start Mastodon Using Docker

Now you can start the Mastodon application using Docker Compose.

docker-compose build
docker-compose up -d

Step 8: Configure Nginx

We’ll set up Nginx as a reverse proxy to forward requests to your Mastodon instance.

  1. Install Nginx:

    sudo apt install -y nginx
  2. Configure Nginx: Create a new configuration file for your Mastodon instance.

    sudo nano /etc/nginx/sites-available/mastodon

    Populate it with the following:

    server {
        listen 80;
        server_name yourdomain.com;
    
        location / {
            proxy_pass http://localhost:3000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
  3. Enable the configuration:

    sudo ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/
  4. Restart Nginx:

    sudo systemctl restart nginx

Step 9: Complete Installation

Ensure everything is running properly:

docker-compose logs

Navigate to your Mastodon instance in a web browser to complete the setup.

Frequently Asked Questions

1. How much does it cost to self-host Mastodon on a VPS?

Costs depend on the provider and specific plan you choose. For example, Contabo VPS starts at 5.99 EUR/mo, while Hetzner Cloud begins at 4.15 EUR/mo. Choose a plan that matches your resource needs, such as CPU and RAM, especially if you anticipate high usage.

2. Can I host multiple Mastodon instances on one VPS?

Yes, it is possible to host multiple Mastodon instances on one VPS, but this requires careful resource management. Each instance will need its own database and may require significant resources to function efficiently. Ensure your VPS has enough CPU power and RAM to support them.

3. Can I customize my Mastodon instance after installation?

Absolutely! Mastodon is highly customizable. You can change themes, add new features, and manage user accounts through the admin dashboard. Many users prefer to tweak their instances to fit specific community needs, such as creating bespoke content moderation tools or installing additional plugins.

By following this guide, you are now equipped to self-host Mastodon on your VPS, allowing for greater control and customization of your social networking experience.