The Fediverse From Home

This project details how I setup my self hosted Fediverse server and connected it to the outside world from my home network. I will cover the why, my technology choices and some of the more technical details but won't give you too much of an onboarding as to what the Fediverse is and how it works. There are plenty of great sites that cover that already.

The philosophy

The first choice you need to make is if you want to self host or not. Back in the early web days it was easier to trust platforms. Early Google provided advert free search and free to use email. Early Twitter made easy to connect with friends and communities, following a simple timeline of updates. These companies were focused on making a good product with real value.

As time went by the pressure for these businesses to turn a profit and please investors/shareholders led to a break of that trust. Advertising became more invasive, algorithms were created to manipulate your attention, conversation became divisive and a lack of sensible policy allowed hate speech and disinformation to spread. On Twitter you have probably witnessed your friends and family get quieter and quieter as they felt less comfortable in their surroundings. I certainly have.

As Elon is demonstrating; sensible, fair and considered policy is hard. With each and every poor decision he is making, the Fediverse (and Mastodon in particular) is seeing huge growth. The easiest way to get started is to jump on an existing server (owned by someone else), but to do so without considering the consequences of that choice is a mistake.

Once again you have to place your trust in a third party. Most server admins look fairly sane but as a history has shown us... things change. They may struggle with costs, moderation or pigeon hole you into discussing just a certain topic. This upheaval from Twitter is an opportunity to own your thoughts, on your own domain and on your own terms. A little extra effort now is worth the investment.

The strength of the Fediverse is decentralisation. No single server is any more important than another. If you come across a particularly nasty server, you (or your server admin) can stop your instance federating with it. Decentralisation makes the platform both easier to moderate and less prone to censorship. By running your own instance you gain that control, but when you are a guest on someone else's instance, it is their choice. What happens when two large instances decide to block each other?

By running your own server you will avoid these concerns and help strengthen the network for everyone.

The software

When I first looked at setting up a Fediverse server I naturally gravitated towards Mastodon. It is by far the most popular and polished software, but it also has fairly demanding requirements. I wanted to start small with something I could easily host on a Rasbperry Pi (or low powered PC) from my home network.

Since setting up my solar hosting project I have grown very fond of the freedom that self hosting provides. It's nice to know where my electricity comes from and who has access to my servers and data (that will be me!).

I discovered a young project called GoToSocial (GtS) that is written in Go and currently in alpha. It fits the requirement for something light and efficient:

A single-user instance with about 100 followers/followees uses somewhere between 50 to 100MB of RAM. CPU usage is only intensive when handling media or processing lots of federation requests.

GoToSocial Docs

GtS provide a multi-architecture Docker container which is my preferred way to setup my self-hosted services.

To expose GtS to the web I am using Cloudflare tunnels. This means I do not need to open ports on my router and I get a little extra security from the Cloudflare network. Exposing alpha software to the web from my home network probably isn't that smart, so I appreciate Cloudflare's additional layer of protection. I also created a private Docker network for GtS so the container doesn't have access to my local network either. Running it this way (via Docker) keeps the code and network securely isolated.

You can use the docker-compose.yaml below to mirror my setup. You'll need to make sure your domain is running via Cloudflare and ensure that you have setup your tunnel in Cloudflare's Zero Trust control panel. Then add your Cloudflare token (export CF_FEDIVERSE_TOKEN=SECRET) to your .bashrc so its available when running docker-compose up.

version: "3.3"

services:
  gotosocial:
    image: superseriousbusiness/gotosocial:0.5.2
    container_name: gotosocial
    hostname: gotosocial
    env_file: ./.settings.env
    restart: always
    volumes:
      - ./data/db:/gotosocial/storage
    networks:
      fediverse:
        ipv4_address: 172.5.1.2

  cloudflared:
    image: cloudflare/cloudflared:latest
    container_name: cloudflared
    hostname: cloudflared
    command: tunnel --no-autoupdate run --token ${CF_FEDIVERSE_TOKEN}
    restart: always
    depends_on:
      - gotosocial
    networks:
      fediverse:
        ipv4_address: 172.5.1.3

  networks:
    fediverse:
      driver: bridge
      ipam:
        driver: default
        config:
          - subnet: 172.5.1.0/16
            gateway: 172.5.1.1

You will also need a .settings.env file in the same directory as the docker-compose.yaml above. This file contains your desired settings for GtS. I set the following options:

GTS_HOST=toot.scott.ee
GTS_PORT=8080
GTS_APPLICATION_NAME=Scott
GTS_ACCOUNTS_ALLOW_CUSTOM_CSS=true

GTS_ACCOUNTS_REGISTRATION_OPEN=false
GTS_ACCOUNTS_REASON_REQUIRED=false
GTS_MEDIA_IMAGE_MAX_SIZE=10485760
GTS_STATUSES_MAX_CHARS=1000

GTS_DB_TYPE=sqlite
GTS_DB_ADDRESS=/gotosocial/storage/sqlite.db
GTS_LETSENCRYPT_ENABLED=false

This ensures the service is running from the correct domain and port. I also disable registration (this instance is just for me) and customise the post length and image size variables. I disable Let's Encrypt as the Cloudflare tunnel is encrypted and they handle SSL for you. A full list of available options can be found in the documentation for GoToSocial.

Creating your first user with a Docker hosted instance of GtS is a bit of a pain. Luckily it is well documented with command line instructions you can copy and paste into your terminal. Once your user is created, make a note of the login credentials in your password manager.

Unlike Mastodon, GtS doesn't provide a front end/client experience. It is just a Fediverse compatible server (at least for now). That means you need to bring your own client. For the web they recommend Pinafore, and for mobile Tusky. Both are open source and a pleasure to use. There are many more clients though and pretty much any of the Mastodon compatible clients will work with GtS too. You can also use tools like Crossposter to relay your tweets and toots in either direction. When setting up your client, you need to enter the URL of your server (toot.scott.ee in my case) and sign in using your username and password.

For administering your GtS server there is an admin settings section available at example.com/admin and user settings can be found at example.com/user — this includes custom CSS if you want to give your profile a lick of paint.

Wrapping up

I appreciate this guide is a little light in places so if you have any questions let me know (links in the footer). I also appreciate that self hosting isn't for everyone... however I do think it gets us closer to the type of Web that we want (and once had). What would the web look like if every home had a server and a decent internet connection?

The Fediverse is just one option for decentralised socialising. There are some very interesting projects that you may also find easier to get started with: Secure Scuttlebutt - via Manyverse / Planetary, Matrix via Element, nostr (which I haven't got my head around yet) and good old RSS with blogs and commenting and all that great stuff.