11 July 2023 - by Jim
How to host your own Mastodon instance for free
There are many guides out there for how to host your own Mastodon instance, to be honest this one doesn’t add much to those already out there but I’m posting this as the entire thing has cost me no money at all so I thought it was worth sharing:
- Sign up for an Oracle Cloud account and set up an Arm instance running Ubuntu, you can probably easily use a 2 CPU, 12GB of RAM instance but feel free to use a 4/24 if you prefer (Some people have reported issues with Oracle and having their accounts suddenly suspended or deleted with no warning. This hasn’t happened to me in around 6 months of using them however I have now upgraded to a pay as you go account to provide an extra level of security/peace of mind. I still haven’t spent a single penny on the set-up though.)
- SSH in and do the usual
apt
updates/upgrades, you need to install Docker,nginx
and any other useful tools you like such asufw
,mosh
etc. - Follow this guide to open ports 80 and 443 on your VM.
- Follow this guide to get Mastodon set-up in Docker. I recommend creating
/opt/mastodon/
and using that as the base directory. - Once the containers are up you need to run a command to create your ID (replacing
yourid
and[email protected]
with your own):
docker exec mastodon_web_1 tootctl accounts create yourid --email [email protected] --confirmed --role Owner
- Success!
Additional things you can do:
- Make use of Cloudflare R2 for your media storage, there’s further help on how to configure this in your
.env.production
file here. - Alternatively, you can add a free 200GB block volume to your Oracle set-up for media storage.
- Set up FakeRelay to automatically pull in hashtags from much bigger servers, this is lighter-weight than using relays and also probably more useful for a single-user instance.
- Set up FediFetcher to add even more content to your instance.
- Enable Elasticsearch - this probably isn’t needed for a single-user instance as it only allows you to search your own posts.
- If you find your media usage is growing too large (try
docker exec mastodon_web_1 tootctl media usage
to get the current totals) then review this blog post for some hints and tips. - Create a backup strategy/script, the main thing to dump and backup is the Postgres DB:
docker exec -t mastodon_db_1 pg_dump -Fc -U postgres -d mastodon -f '/export.dump'
and you can then copy it out to your local filesystem:
docker cp mastodon_db_1:/export.dump /opt/mastodon/backups/export.dump
Obviously if your media is hosted locally you also need to back that up, if using R2 or any other S3 provider this is one less thing to worry about.