How to host your own mastodon server on vps

Running your own Mastodon server on a VPS is an excellent way to enjoy an efficient and secure Mastodon experience. In this article, we’ll guide you through the installation and configuration of a Mastodon server on Linux VPS.

It is essential to select a server that meets your requirements. That means selecting one with an appropriate moderation policy, privacy guidelines and content focus.

What is Mastodon?

Mastodon is a decentralized social media platform that enables users to post messages, comments and links across a network of independent servers. It offers various features like hashtags, emojis, audio/video posts, polls and more that make Mastodon unique from other social media platforms.

Free and open source, unlike Twitter or Facebook, this platform puts decision making back in the hands of its users – giving you control over what information can and cannot be shared online.

Mastodon can be installed on a VPS with just two requirements: a Linux server and internet access. Popular Linux distributions like Debian or Ubuntu offer plenty of features and packages for you to choose from, making these two choices ideal for beginners or experienced Linux users alike.

How to Host Your Own Mastodon Server on a VPS


  • A VPS running Ubuntu 20.04 or Debian 11 that you have root access to
  • A domain name (or a subdomain) for the Mastodon server, e.g.
  • An e-mail delivery service or other SMTP server

System repositories

Make sure curl, wget, gnupg, apt-transport-https, lsb-release and ca-certificates is installed first:

apt install -y curl wget gnupg apt-transport-https lsb-release ca-certificates


curl -sL | bash -


wget -O /usr/share/keyrings/postgresql.asc
echo "deb [signed-by=/usr/share/keyrings/postgresql.asc] $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/postgresql.list

System packages

apt update
apt install -y \
imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \
g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf \
bison build-essential libssl-dev libyaml-dev libreadline6-dev \
zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev \
nginx redis-server redis-tools postgresql postgresql-contrib \
certbot python3-certbot-nginx libidn11-dev libicu-dev libjemalloc-dev


corepack enable
yarn set version classic

Installing Ruby

We will be using rbenv to manage Ruby versions, because it’s easier to get the right versions and to update once a newer release comes out. rbenv must be installed for a single Linux user, therefore, first we must create the user Mastodon will be running as:

adduser --disabled-login mastodon

We can then switch to the user:

su - mastodon

And proceed to install rbenv and rbenv-build:

git clone ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec bash
git clone ~/.rbenv/plugins/ruby-build

Once this is done, we can install the correct Ruby version:

RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.0.4
rbenv global 3.0.4

We’ll also need to install bundler:

gem install bundler --no-document

Return to the root user:



Setting up PostgreSQL

Performance configuration (optional)

For optimal performance, you may use pgTune to generate an appropriate configuration and edit values in /etc/postgresql/15/main/postgresql.conf before restarting PostgreSQL with systemctl restart postgresql

Creating a user

You will need to create a PostgreSQL user that Mastodon could use. It is easiest to go with “ident” authentication in a simple setup, i.e. the PostgreSQL user does not have a separate password and can be used by the Linux user with the same username.

Open the prompt:

sudo -u postgres psql

In the prompt, execute:



Setting up Mastodon

It is time to download the Mastodon code. Switch to the mastodon user:

su - mastodon

Checking out the code

Use git to download the latest stable release of Mastodon:

git clone live && cd live
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)

Installing the last dependencies

Now to install Ruby and JavaScript dependencies:

bundle config deployment 'true'
bundle config without 'development test'
bundle install -j$(getconf _NPROCESSORS_ONLN)
yarn install --pure-lockfile

The two bundle config commands are only needed the first time you’re installing dependencies. If you’re going to be updating or re-installing dependencies later, just bundle install will be enough.

Generating a configuration

Run the interactive setup wizard:

RAILS_ENV=production bundle exec rake mastodon:setup

This will:

Create a configuration file
Run asset precompilation
Create the database schema
The configuration file is saved as .env.production. You can review and edit it to your liking. Refer to the documentation on configuration.

You’re done with the mastodon user for now, so switch back to root:


Setting up nginx

Copy the configuration template for nginx from the Mastodon directory:

cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon
ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon

Then edit /etc/nginx/sites-available/mastodon to replace with your own domain name, and make any other adjustments you might need.

Reload nginx for the changes to take effect:

systemctl reload nginx

Acquiring a SSL certificate

We’ll use Let’s Encrypt to get a free SSL certificate:

certbot --nginx -d

This will obtain the certificate, automatically update /etc/nginx/sites-available/mastodon to use the new certificate, and reload nginx for the changes to take effect.

At this point you should be able to visit your domain in the browser and see the elephant hitting the computer screen error page. This is because we haven’t started the Mastodon process yet.

Setting up systemd services

Copy the systemd service templates from the Mastodon directory:

cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/

If you deviated from the defaults at any point, check that the username and paths are correct:

$EDITOR /etc/systemd/system/mastodon-*.service

Finally, start and enable the new systemd services:

systemctl daemon-reload
systemctl enable --now mastodon-web mastodon-sidekiq mastodon-streaming

They will now automatically start at boot.

Hurray! This is it. You can visit your domain in the browser now!

Configuring Postfix

If you want to host your own Mastodon server, there are a few things you must take into account before beginning. A domain name and virtual server both come with monthly or yearly prices which vary depending on which hosting company you select.

Domains are a way for you to identify yourself on the internet and connect with others using that same name. You can purchase one from any registrar such as Rad Web Hosting, Namecheap or Gandi, though the cost varies depending on which domain name you select.

Additionally, you’ll require a virtual server to run the code that keeps your Mastodon server up and running. You can purchase one of these Linux VPSs from hosting providers like RadVPS, Hetzner, Exoscale or Scaleway.

Before you can begin setting up your Mastodon server, you’ll need to configure Postfix. This mail transfer agent is designed for speed, simplicity of administration and security and it can be installed on a variety of UNIX-like operating systems like AIX, BSD, HP-UX, Linux, MacOS X or Solaris.

Configuring Postfix can be a bit of a hassle, but its website provides comprehensive documentation about every possible setting. If you’re new to Linux programming, O’Reilly’s Postfix: The Definitive Guide may offer some additional assistance.

If you plan to send emails, it is essential that they be encrypted so service providers can recognize them as genuine. A software package such as PGP can help create an encrypted message which your email provider can recognize.

Once encryption is set up, it’s time to configure SMTP (Sender Machine Translation) so the messages can be sent out. You can do this using a command from your terminal.

Once that’s done, run the Postfix email send command to check if you can send emails out of your server. If not, there may be an issue with either your Postfix configuration or email address; therefore, you need to rectify it.

Finally, ensure your database is configured correctly and has the correct database credentials. To do this, edit /etc/postfix/virtual and add in the necessary lines.

Configuring PHP

Mastodon is an open-source social media platform not backed by any major company. It’s created to reduce the level of control found on platforms like Facebook, Twitter, and Instagram.

Decentralized networks enable users to communicate and collaborate through ActivityPub, the W3C’s open standard for social networking. This promotes knowledge-sharing without the need for a central point of ownership or management.

Mastodon provides hundreds of distinct instances for users to register with and create accounts on. Each instance has its own set of rules regarding who can join and how the site is moderated.

Mastodon stands out among other social media platforms in that users can select which community they wish to join. This gives them more control over their experience and guarantees everyone a voice within the network.

However, it comes with risks. In some instances, the individual or group who owns the server may run out of money and need to shut it down; alternatively, they might have a different perspective on moderation than you do.

Mastodon can present long-term challenges for those on its network. For example, white supremacist groups have used Mastodon as part of their propaganda efforts.

To avoid this, make sure you select a reliable and secure server. You can find such servers on Mastodon as well as other websites that list servers by user or category.

Once you’ve chosen a server to sign up with, simply go to their website and complete your profile. From there, you can begin posting content and following other users.

If you have any inquiries, don’t hesitate to contact our Support team. We are more than happy to help!

Before Mastodon can be installed on your VPS, you must configure the PHP environment. This includes setting the appropriate version of PHP and installing any necessary extensions. This guide outlines the basics; however, you are free to customize these settings according to your individual needs.


Avatar of editorial staff

Editorial Staff

Rad Web Hosting is a leading provider of web hosting, Cloud VPS, and Dedicated Servers in Dallas, TX and Phoenix, AZ.