10 min read

Self-Host Mastodon: Run Your Own Fediverse Server (2026)

Deploy Mastodon with Docker Compose and reach it from anywhere with a permanent Localtonet domain. Own your identity, your moderation, your data

๐Ÿ˜ Mastodon ยท Fediverse ยท Self-Host ยท ActivityPub

Every centralized platform eventually changes its rules, its algorithm, or its ownership, and you find out about it the same day everyone else does. Mastodon, the open-source social network built on ActivityPub, lets you run your own server instead: your own moderation policy, your own uptime, your own data, while still talking to millions of accounts across the wider fediverse. The hard part has never been Mastodon itself, it is reaching it reliably from a domain that will still work in five years. This guide covers installing Mastodon with Docker Compose and exposing it correctly with Localtonet.

Open source, AGPLv3 licensed, since 2016 Federates with the entire ActivityPub network Your data, your moderation, your rules

Why Run Your Own Corner of the Fediverse

Joining someone else's Mastodon instance solves the platform-ownership problem, but not the platform-dependency problem. Your account, your followers, and your posting history still live on infrastructure someone else controls, and that admin's decisions, downtime, and moderation calls become yours by default.

Running your own instance keeps every one of those decisions in your hands, while ActivityPub still lets you follow, and be followed by, accounts on every other Mastodon, Pixelfed, and Lemmy server out there.

You are not leaving the network, you are just hosting your own piece of it.

What Is Mastodon?

Mastodon is an open-source, AGPLv3-licensed social network built on Ruby on Rails, first released in 2016 by Eugen Rochko. It speaks ActivityPub, the same federation protocol behind Pixelfed and Lemmy, which is what lets independently run servers interoperate as one network instead of walled gardens.

๐ŸŒ Federated by design Your server talks to any other ActivityPub server. Followers on mastodon.social can follow an account on your own instance with no special setup.
๐Ÿ‘ค Single-user mode Running it just for yourself. Single-user mode disables public registration and redirects the homepage straight to your profile.
๐Ÿ›ก๏ธ You set the moderation rules Block, mute, or defederate from entire servers at your own discretion, no appeals process to a company you don't work for.
๐Ÿ†“ Free and open source No subscription tier, no algorithm deciding what your followers see. The AGPLv3 license keeps it that way.
Check your hardware before you start

Mastodon's Sidekiq background workers and media processing are the heaviest part of running it. Plan for at least 4GB of RAM and a 2-core CPU for a single-user instance, 8GB and 4 cores if you expect other people to sign up, plus 50GB of storage minimum. A single-user instance can run comfortably on hardware as modest as a Raspberry Pi 4 with 4GB of RAM.

Install Mastodon With Docker Compose

๐Ÿ”‘ Generate the required secrets

Mastodon needs three secret values before it will start: SECRET_KEY_BASE, OTP_SECRET, and a VAPID key pair for push notifications.

Terminal
docker run --rm tootsuite/mastodon:v4.5.10 bundle exec rake secret
docker run --rm tootsuite/mastodon:v4.5.10 bundle exec rake secret
docker run --rm tootsuite/mastodon:v4.5.10 bundle exec rails mastodon:webpush:generate_vapid_key

Save all four values, you will paste them into your environment file next.

โš™๏ธ Configure the environment file

Create .env.production with your domain, database, Redis, SMTP, and the secrets from the previous step. The LOCAL_DOMAIN value is the one setting you should treat as permanent, more on that below.

.env.production
LOCAL_DOMAIN=mastodon.example.com
SECRET_KEY_BASE=your_generated_value
OTP_SECRET=your_generated_value
VAPID_PRIVATE_KEY=your_generated_value
VAPID_PUBLIC_KEY=your_generated_value
DB_HOST=db
DB_NAME=mastodon
DB_USER=mastodon
DB_PASS=your_db_password
REDIS_HOST=redis
SMTP_SERVER=your_smtp_host
SMTP_PORT=587
SMTP_LOGIN=your_smtp_user
[email protected]

๐Ÿณ Start the stack

A minimal Docker Compose setup runs five services: db (Postgres), redis, web (the Rails app on port 3000), streaming (the WebSocket API on port 4000), and sidekiq (background jobs).

Terminal
docker compose up -d db redis
docker compose run --rm web bundle exec rails db:migrate
docker compose up -d

Remote Access With Localtonet

Mastodon's own documentation notes that the streaming API can run on its own subdomain, which avoids needing a local reverse proxy just to split traffic between the two services. That maps directly onto two separate Localtonet HTTP tunnels, each with a custom domain and free auto-provisioned HTTPS.

1

Point your DNS at Localtonet

Create records for both mastodon.example.com and streaming.example.com using Localtonet's DNS Manager, or your own DNS provider if you manage records elsewhere.

2

Tunnel the web service

Create an HTTP tunnel at localtonet.com/tunnel/http pointing to 127.0.0.1:3000, and map mastodon.example.com to it as a custom domain.

3

Tunnel the streaming service

Create a second HTTP tunnel pointing to 127.0.0.1:4000, mapped to streaming.example.com.

4

Set STREAMING_API_BASE_URL

In .env.production, add STREAMING_API_BASE_URL=wss://streaming.example.com so Mastodon's own web client knows where to open its WebSocket connection, then restart the stack.

โš ๏ธ Most tutorials skip this step: your domain is permanent the moment federation starts

Once other servers have federated with your instance under a given domain, changing LOCAL_DOMAIN breaks that federation history, your account identity is tied to the domain, not just a database row. Decide on your domain before your first post goes out, not after.

๐Ÿ”’ Security and Moderation

๐Ÿ”‘ Turn on two-factor authentication

Enable 2FA on your own account from the security settings the moment setup finishes, before you invite anyone else or start posting.

๐Ÿ‘ค Consider single-user mode

If this instance is just for you, single-user mode disables public registration entirely and redirects the homepage straight to your profile, removing an entire category of moderation work.

๐Ÿšซ Federation is a moderation tool too

You can block or limit federation with specific servers at the instance level, not just mute individual accounts. Use it if a server is a consistent source of abuse toward your instance.

๐Ÿ”„ Keep Mastodon updated

Security patches land in point releases regularly. Follow the project's own account for release notifications, and budget time for the database migration step that follows most upgrades.

Keep It Running Permanently

Set restart: unless-stopped on every service in your Docker Compose file so the stack survives a Docker restart. For the tunnels themselves to survive a full machine reboot, install the Localtonet client as a service once with localtonet --install-service --start-service, both custom domains come back automatically without you touching anything.

Self-Hosted Mastodon vs. an Existing Instance vs. Twitter/X

FeatureTwitter / XJoining an existing instanceSelf-hosted Mastodon
Who sets the moderation rulesThe companyThat instance's adminYou
Account portabilityNonePossible, but you rely on that server staying upFull control over uptime and history
CostFree tier with ads, paid tiers for moreUsually free or a small donationYour own hosting, roughly the cost of a small VPS or spare hardware
Setup effortNoneNoneAn evening, plus ongoing maintenance

The honest trade-off: joining an existing, well-run instance is genuinely the lower-effort path into the fediverse, someone else handles updates, moderation, and uptime for you. Self-hosting is worth the extra effort specifically when you want your account identity, your moderation policy, and your uptime to answer to no one but you.

๐Ÿ›  Tips for Running a Healthy Instance

๐Ÿ“ง Set up SMTP before you need it Password resets and email confirmations depend on it working. Test it during setup, not during a lockout.
๐Ÿ’พ Back up Postgres and Redis regularly A scheduled pg_dump plus a copy of the Redis RDB file covers the two stateful pieces that actually matter.
๐Ÿงน Clean up old media automatically Remote media cached from federated posts grows without bound by default. A scheduled cleanup job keeps disk usage in check.
โ˜๏ธ Offload media to S3-compatible storage if you grow Keeps your local disk from filling with attachments as your instance and its federated cache grow over time.

Troubleshooting Common Issues

SymptomLikely causeFix
Blocked hosts error in the browserThe domain you are visiting is not in Rails' allowed host listConfirm LOCAL_DOMAIN in .env.production matches the domain you mapped to the tunnel exactly
Live timeline never updatesThe web client cannot reach the streaming serviceConfirm STREAMING_API_BASE_URL points to the streaming tunnel's domain and that tunnel is running
No confirmation or password reset emailsSMTP is not configured or credentials are wrongTest SMTP settings directly with a mail testing tool before assuming Mastodon itself is broken
Database migration fails during an upgradeInsufficient RAM during asset precompilationAdd temporary swap space or upgrade RAM before running the migration step

Frequently Asked Questions

Can I change my instance's domain later?

Not without breaking federation history. Your account identity on the fediverse is tied to your domain, so pick one you intend to keep for good before you start posting.

Do I need two separate domains for a working instance?

No, a single domain with a local reverse proxy routing paths works too. Two domains, one for the web app and one for streaming, is simply the path Mastodon's own documentation describes as avoiding extra proxy overhead, and it maps cleanly onto two Localtonet tunnels.

How much does self-hosting Mastodon cost?

Mastodon itself is free and open source. Your actual cost is whatever hardware or VPS you run it on, plus optional S3 storage if you offload media, roughly what a small VPS costs per month if you are not already running suitable hardware.

Will my instance be able to follow accounts on mastodon.social or other servers?

Yes. ActivityPub federation works the same way regardless of who runs the server, your instance and any other Mastodon, Pixelfed, or Lemmy server can follow and interact with each other by default.

Do I need to run this for multiple users?

No. Single-user mode is a supported, first-class configuration that disables public registration and points the homepage at your own profile.

Does my server need to stay online all the time?

Federated posts are delivered asynchronously, so brief downtime does not lose data, but extended downtime delays delivery and can affect how other servers see your instance's reliability. Running the stack and the Localtonet client as background services keeps this from being a manual chore.

Is Mastodon hard to keep updated?

Updating means pulling new container images and running a database migration, which is straightforward but can be memory-intensive during asset precompilation. Budget a maintenance window and enough RAM or swap for the migration step.

Ready to Run Your Own Corner of the Fediverse?

Deploy Mastodon with Docker Compose, then reach it through a permanent custom domain with Localtonet, no port forwarding, no server rental. Free to start, no credit card required.

Get Started Free โ†’

Localtonet is a secure multi-protocol tunneling and proxy platform designed to expose localhost, devices, private services, and AI agents to the public internet supporting HTTP/HTTPS tunnels, TCP/UDP forwarding, mobile proxy infrastructure, file server publishing, latency-optimized game connectivity, and developer-ready AI agent endpoint exposure from a single unified control plane.

support