How To Setup and Install Mastodon (Decentralised Social Media)

Mastodon is a decentralised social media platform that you can host yourself.

Jan 12th, 2021

How To Setup and Install Mastodon (Decentralised Social Media)

The topic of de-platforming has been discussed a lot lately between Trump getting booted of Twitter and Parler getting kicked off AWS. With most major social media sites cracking down on certain users people have searched for alternatives. Unfortunately some of the alternatives have gathered a less than desirable reputation for its userbase. In this I'm going to explain how you can automatically set up mastodon on you server with an Ansible script.

The Deets

Mastodon is a social media site unlike any other. Instead of accessing a website running on some data centre owned by a giant tech company, Mastodon is an open-source software project that anyone can use to create their own customizable instance. Each mastodon instance can communicate with each other and the site owner determines what can and cannot be done on their instance.

The Technical Details

Before you start installing things you'll need to harden your SSH and set up fail2ban as recommended in the Mastodon documents. I previously wrote an article on how you can do that which can be found here.

Next you'll need to set up your DNS record for your domain. If you bought your domain with GoDaddy or any other domain registry then just point your record to your server IP address. I personally use Bind9 to host a Name Server on my VPS.

If you wish to install the entire dependancies and services from scratch then check out my video above. It's always good to at least attempt to do this from source both because you know exactly whats going on your server and because using Snap packages and other containers have a range of issues. However in this article I will show you how to install all services on your instance with an Ansible playbook provided by the creators of Mastodon. The playbook can be seen in the github below.

Some things to note when running the playbook is that it's wise to add the sudo password command as you mightn't be able to type it in when the script is running remotely. Simply run the following on your Local Machine.

ansible-playbook bare/playbook.yml --skip-tags=postgres -u <YOUR USER> --extra-vars="mastodon_db_password=<YOUR MASTODON PASSWORD> ansible_sudo_pass=<YOUR SUDO PASSWORD> mastodon_host=<YOUR DOMAIN>"

That's basically it. One the playbook runs without error simply go onto your server and run the following commands.

    ssh yourmachine
    su - mastodon
    cd ~/live
    RAILS_ENV=production bundle exec rake mastodon:setup

Unlike a typical social media site you'll be able to have a more close-knit experience and you'll have complete control over your data and who uses your instance. If you get stuck there are some additional explainations in the video above.

Stay happy and stay private.