25th Anniversary Savings | 25% Off Dedicated Servers*Shop Now
25th Anniversary Savings | 25% Off VPS Hosting* †††Shop Now
Limited Inventory: High-Performance AMD-Powered Servers Now Available.* Shop Now >
Dedicated Hosting Deals | From $99/moShop Now

How to Set Up a Mastodon Server

Posted on by Neil Golden
Reading Time: 5 minutes

What is Mastodon?

Mastodon is a free, open source software written in Ruby on Rails and JavaScript (React.js and Redux). It is designed for running self-hosted social networking services. In terms of microblogging features, Mastodon is very similar to Twitter. It provides a huge number of running Mastodon nodes, and every instance has its own moderation policy, code of conduct, and terms of service.

Users have an opportunity to select a server that fits their needs and keep access to a larger social network. In addition, Mastodon is a part of Fediverse server platforms, which allows users to interconnect with platforms like MisskeyFriendica, Owncast, PeerTube, and many others. 

Why Run Your Own Mastodon Server?

The advantages of running your own Mastodon server are numerous. Some of the biggest advantages are:

  • You are not quarantined on your server, without any kind of problems, you can follow anyone found on any other server, and they can follow you back in return. Furthermore, you can communicate with users on any other server just like you are on the same one.
  • The rules you set are the only rules you will follow, meaning you are in absolute control and not subject to anybody's regulations.
  • It is possible to choose the type of users that will have access to your server. You can be the only one who is running the server, or you can set it up so your family, friends or a certain community has access to the server.

Mastodon Server Requirements and Prerequisites

Mastodon has extensive documentation for setting up your account and running your own server. The following list is a guideline of what you need to successfully follow this tutorial and install and run your own Mastodon server:

  • VPS or other server - a server running Ubuntu 20.04 or Debian 11 with root access. The server will always be online and running the Mastodon code.
  • Domain name (or subdomain) - it provides a way of identification on the network, and a method for other users to access your server. Setting up a domain name is extremely easy. It can be done with just a few clicks once you have purchased a server.
  • Email provider - Mastodon needs your email address in order to send you various notifications and confirmation links by email. In addition, administrators need an e-mail delivery service or other SMTP server installed.
  • Additional storage - this is one of the optional mastodon server requirements, but considering that Mastodon will store data on your VPS server's hard drive, it is always good to have additional storage.

Mastodon Server Setup

There are many ways to install and run Mastodon. This tutorial shows you how to start Mastodon server hosting on servers running CentOS 7 using Docker. You also learn how to join the Mastodon community.

Step 1: SSH Into Your Server and Add a Mastodon System User

This tutorial uses mastodonuser as a username, but you can choose your own. Create a user using the following command.

adduser mastodonuser

Grant mastodonuser root privileges and login as the user with this command.

usermod -aG sudo mastodonuser
su - mastodonuser

Step 2: Install Docker

Run the Docker installation as your created user. Start by updating your packages.

yum -y update

Install Docker by installing the docker-io package.

yum -y install docker docker-registry

Use the following command to set the Docker service to start at boot.

systemctl enable docker.service

This command will start the Docker service.

systemctl start docker.service

Verify your work by checking the status of Docker.

systemctl status docker.service

Step 3: Install Docker Compose

With Docker Compose, you will be able to create a text file that will allow you to manage and run containers. Use the following command to install Docker Compose.

yum install docker-compose

Step 4: Install Mastodon on Your Server

Navigate to your /home/mastodon directory using the cd command.

cd /home/mastodon

Download Mastodon by cloning the GitHub repository.

git clone https://github.com/mastodon/mastodon

Again, navigate to the new Mastodon directory using the cd command and edit the docker-compose.yml file using the file editor of your choice. This tutorial uses the Vim editor.

cd mastodon
vim docker-compose.yml

Press the i key to enter insert mode to edit the file. Comment out every line which begins with the word build, which should be three lines, then save and exit the file. If you are using Vim, save and exit the file by typing :wq! and pressing Enter.

Next, ensure the /home/mastodon/mastodon/.env.production file exists. If the file does not exist, create an empty file named .env.production in the /home/mastodon/mastodon/ directory using the following command.

touch .env.production

Once completed, or if the file already exists, continue with the Mastodon installation by entering the following command.

docker-compose run --rm web bundle exec rake mastodon:setup

Once the installation is complete, you will be asked for a domain name, enter your domain name, and go with the default settings for everything else. The default settings should look like the example below.

Domain name: yourdomainame.com

Single user mode disables registrations and redirects the landing page to your public profile.
Do you want to enable single user mode? - n.

Are you using Docker to Run Mastodon? - y.

PostgreSQL host: db
PostgreSQL port: 5432
Name of PostgreSQL database: postgres
Name of PostgreSQL user: postgres
Password of PostgreSQL user - leave it empty, just press ENTER.

Redis host: redis
Redis port: 6379
Redis Password  - leave it empty, just press ENTER.

Do you want to store uploaded files on the cloud? - n.

Do you want to send e-mails from localhost? - n.

Look for your default SMTP login and password, and insert the details into the .env.production, it should look like this:

SMTP_LOGIN=
SMTP_PASSWORD=

When you see the prompt to send a test email with this configuration, choose yes and confirm you have received the email. After the wizard is complete, the configuration will be recorded in the .env.production file. 

Type the username for the admin user and save your password.

Step 5: Start an NGINX Reverse Proxy

Install NGINX using the following command.

yum install nginx

You have to delete the default NGINX profile and create a new one. Delete the default NGINX profile with these commands.

rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-enabled/default

If by any chance there are no sites-available and sites-enabled directories in the /etc/nginx directory, it means there is no default NGINX profile. To create them, navigate to your /etc/nginx directory using the cd and mkdir commands.

cd /etc/nginx/ mkdir sites-available
cd /etc/nginx/ mkdir sites-enabled

The next command creates a new NGINX profile.

touch /etc/nginx/sites-available/mastodon

You can create a symbolic link to access the profile. To do so, use the following command.

ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon

From the following GitHub link, copy the content and paste it into the sites-available file you just created.

vim /etc/nginx/sites-available/mastodon

Do not close the editor yet, as you will have to replace all of the domain names with your domain name in the file. Remember that you should not include www with your domain name. Once completed, save and exit the file.

Step 6: Install an SSL Certificate

To install an SSL certificate, you need to install Snap on your system and use Snap to install Certbot. You can use Certbot to install new and existing SSL certificates. Install Snap using this command.

yum install snapd

In addition to Snap, you must install core, the snapd runtime environment. Use the following command to install core.

yum install core && snap refresh core

Install Certbot with the following command.

snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot

The next command will download a certificate for your domain.

certbot certonly --nginx

Use the following command to renew Certbot.

certbot renew --dry-run

Uncomment the ssl_certificate and ssl_certificate_key lines in the  /etc/nginx/sites-available/yourdomain.com.conf file.

Finally, restart nginx using the following command to complete the SSL certificate setup.

systemctl restart nginx

Using Mastodon

Open your web browser and in the URL bar enter your Mastodon domain name. The login page will be prompted and you can login with your Mastodon accounts. If you want to open the administration page, simply navigate to yourdomain.com/admin/settings/edit and start the Mastodon server setup.

Wrapping Up

You have successfully installed Mastodon on your server. You can now start using Mastodon server hosting, or run a Mastodon instance.

Liquid Web offers VPS Hosting, Cloud Dedicated Servers, and Dedicated Servers for your Mastodon hosting needs. With the knowledge of how to run your own Mastodon server, hosting it with Liquid Web gives you a provider that can grow with your community. Contact our sales team to get started today.

Avatar for Neil Golden

About the Author: Neil Golden

Neil contributed to solving the complex puzzle of evolution for a long time by obtaining his Ph.D. in Archaeology. These days, he digs the Linux servers in his role within the Liquid Web Monitoring Department instead of Paleolithic stone tools in the caves on archaeological sites. Instead of mammoths, he is now hunting for bugs on Linux servers. He has written numerous scientific and technical articles because writing is one of his biggest passions. In his free time, Neil composes music, reads novels, and travels the world.

Latest Articles

How to Install the Pip Package Manager on AlmaLinux

Read Article

cPanel EA NGINX vs Engintron: What is the Best Option?

Read Article

cPanel EA NGINX vs Engintron: What is the Best Option?

Read Article

Troubleshooting: Too Many Redirects

Read Article

What Is a Time Series Database? How It Works & Use Cases

Read Article