chebe: (Default)
chebe ([personal profile] chebe) wrote2022-12-19 01:11 am

Setting up your own mastodon instance

So simply joining an existing mastodon instance is not enough for you, you want control? Set up your own! The official documentation has a page about that, including listing a bunch of specialised hosting providers that will do this installation bit for you. But we like the more difficult road with the rewarding learning curve around here. Make sure you get get your linux box prepared, and we'll get into setting up a mastodon instance on local hardware, running linux, without docker, and without cloud storage.


  • Step 1; Get to installing mastodon

  • Okay. I don't want to talk about this hardware, not since the company fucked up so badly on the socials. But I already have the hardware, and see no point in letting it go to waste. It's a Raspberry Pi 4 (4GB). I found a nice, heavy, case for it too, with built-in fan. (If you get something like this don't forget to install the libraries/scripts to use the hardware.)

    I also discovered that you can now install Raspbian OS directly onto a USB-connected hard-drive (through Raspberry Pi Imager), and not use an SD card at all. So I'm running with a 1TB SSD. I'm also running Raspbian OS 64bit (to have access to a specific version of PostgreSQL). It runs so much faster than my previous set-ups!

    The process is described, step-by-step, in all its many, many steps, in this PiMyLifeUp guide. Which follows the official documentation pretty closely. But it isn't great at explaining things, just tells you to do it. All I can say is that it seems like less and less work each time you do it.

    When asked if I wanted to create a single-user instance I selected No, even though it is just for me. Because I can go to Preferences > Administration > Server Settings > Registrations and set it to 'Nobody can sign up', to get the same effect, but gives me the opportunity to change that easily later on, even if I just want the extra accounts for myself.

    No, when asked if using docker.
    No, when asked if I want to store uploaded files on the cloud.
    The default options for SMTP, and everything else, in that guide worked for me.

    There are a couple of security things you should do that the guide doesn't go through. If you use the iptables configs given, and are getting error messages about state it seems that has been deprecated, so you should change;
    -m state to -m conntrack and
    --state to --ctstate

    You might also need to select the legacy version of iptables;
    sudo update-alternatives --config iptables

    My biggest issue was with certbot and DNS, but I covered that in the previous post. Hopefully everything goes smoothly and you can log in! But if you do feel like you messed something up you can always rerun the configuration process, the one that is started with;
    RAILS_ENV=production bundle exec rake mastodon:setup
    But, you will probably need to log into postgresql and drop the table (e.g. mastodon_production) first.


  • Step 2; Get to customising mastodon

  • The aforementioned control that I wanted? Yeah, it was over how the instance looks. I miss the era of ugly home pages, and am doing my part to bring it back.

    Once you're logged into the website as the admin you can go to Preferences > Administration > Server Settings > Appearance, and you will find a text box for applying Custom CSS styling. I found this to be really frustrating very quickly though, because a lot of the colour scheme is defined as, for example, 25% darker than base colour x. If you style one aspect of a component it won't affect everything as you would hope. Instead you need to crack open the code!

    We checked out the mastodon codebase earlier, so we can easily edit it in place. The file with the colour scheme is variables.scss. The main targets are $classic-base-color, $classic-primary-color, $classic-secondary-color, and $classic-highlight-color. Simply replace the hex values with your hex values, save and close.

    Another thing you might want to customise is the default images, which you can find in the images folder. They're (mostly) .svgs, so you can open them in a text editor and edit. I just changed some fill colours and some stop-colors, but you could replace them completely if you'd like.

    There is another image, preview.png, that is the one that gets used as the 'server thumbnail', on the About page, and to left hand side when viewing other servers. You can replace it here, but it is really easy to update it through Preferences > Administration > Server Settings > Branding, so I don't think there's much need to do it here.

    After you've made your customisations you need to recompile the css/js assets.
    sudo su mastodon
    cd ~/live

    if you haven't already. First we delete the old ones, then we compile the new ones;
    RAILS_ENV=production bundle exec rake assets:clobber
    RAILS_ENV=production bundle exec rake assets:precompile


    Go back to regular user, and restart your instance;
    exit
    sudo systemctl restart mastodon-sidekiq
    sudo systemctl reload mastodon-web


    Hit refresh in your browser, don't be in a hurry, and you will see the changes picked up! Enjoy your power, wield it creatively.


  • Step 3; Should you set up an instance for other people?

  • Maybe you don't just want a single-user instance, maybe you want to hang out with friends. Some people with a lot of experience in this field have shared valuable insights.