How to create a Mastodon server
Running your own Mastodon server gives you full control over your data and community moderation, providing a personalized, privacy-friendly, and ad-free experience.
What are the requirements for a Mastodon server?
You can launch a small server and expand it as needed to keep pace with your growing community. To set up a Mastodon server you need:
-
VPS or another server: While you can run Mastodon on a local server, a Virtual Private Server (VPS) is more flexible and easier to manage. Ideally, the server should run Ubuntu 20.04 or Debian 11 and provide root access for necessary configurations.
-
Domain or subdomain: You’ll need a domain or subdomain to identify your Mastodon server, making it easier for users to find and connect to your instance.
-
Constant online availability: Your server must be online 24/7 to keep your Mastodon instance accessible to others.
-
Email provider: Mastodon sends notifications and confirmation links via email, so you’ll need an email provider. While you can install your own SMTP server, third-party services like Mailgun, SparkPost, or SendGrid are often more practical.
-
Object Storage Provider (optional): Using an Amazon S3-compatible object storage provider is recommended, as Mastodon stores data like images, videos, and other media on the server. This additional storage helps your instance run smoothly and provides ample space for user data.
Cost-effective, scalable storage that integrates into your application scenarios. Protect your data with highly secure servers and individual access control.
Your server should also meet the following minimum technical requirements:
- CPU/Computing Power: min. 2 cores
- RAM/Memory: min. 2 GB
- Hard disk storage: min. 30 GB
Mastodon relies on a PostgreSQL database to store user data and other information. With a large user base, database access can become intensive. Ensure your database is well-optimized and that sufficient CPU and RAM resources are available to handle these accesses efficiently.
How to host a Mastodon server with IONOS VPS
Ready to start your own Mastodon instance but unsure which VPS plan suits your needs? IONOS offers high-performance VPS plans with dedicated resources and unlimited traffic, all at affordable prices.
For a simple Mastodon server, the VPS Linux S plan from IONOS is an ideal choice. It offers 80 GB of storage space and up to 1 Gbit/s bandwidth. If you require more resources, you can easily upgrade to a higher service plan.
Possible Mastodon server scenarios and corresponding IONOS plans
When deciding on a suitable VPS plan, you should assess the potential number of users of your Mastodon instance. Depending on the expected traffic, we recommend the following IONOS plans:
Mastodon server scenario | Suitable IONOS VPS server |
---|---|
Up to 100 people | VPS Linux M |
100-1000 people | VPS Linux L |
1000-10000 people | VPS Linux XL |
from 10000 people | VPS Linux XXL |
You can run your Mastodon server in parallel with other services. For a small user base, you can start with these plans:
Mastodon server scenario | Suitable IONOS VPS server |
---|---|
Parallel operation of a simple website | VPS Linux M |
Parallel operation of Voice Servers | VPS Linux M |
Parallel operation of online shops | VPS Linux L |
How to create a Mastodon server step by step
Step 1: prepare server
Most hosting providers allow you to select the operating system during setup. Mastodon runs best on Ubuntu 20.04 or Debian 11, so choose one of these if available. After your VPS is set up, connect to your server via SSH. You can use a terminal (Linux/Mac) or an SSH client like PuTTY (Windows) to do this.
Replace your_server_ip
with the IP address of your VPS.
To secure your system, use SSH keys and configure firewall rules with iptables leaving only the HTTP(S) and SSH ports open. Next, point the A-record of your domain or subdomain to your VPS’s IP address. For IPv6, add an additional AAAA record.
Update the package manager and the system packages:
Step 2: install the required packages
Mastodon requires several packages and dependencies to function properly. These include Node.js, Yarn, PostgreSQL, Redis and Nginx.
Install basic packages first:
Node.js
PostgreSQL
System packages
Yarn
Ruby
Mastodon is written in Ruby and therefore requires Ruby and Bundler. To do this, first create the user under which Mastodon is to run:
Now switch to the user account you created:
Install rbenv
and rbenv-build
:
Once complete, install the correct version of Ruby and the Bundler:
Use exit
to return to the root user.
Step 3: configure PostgreSQL
PostgreSQL is used by the Mastodon server to store and manage data. After installing the database server, switch to the Postgres user to access the PostgreSQL shell:
Mastodon connects to the database server without a password, so the Linux system username and the database username must match. Execute the following commands in the PostgreSQL shell to create the database:
You can enhance PostgreSQL database performance by adjusting system resources. A useful tool for this is the configuration generator pgTune. Enter details like the number of CPU cores and RAM size to get an optimized PostgreSQL configuration, which you then apply in postgresql.conf
.
Step 4: install Mastodon
Next, return to the Mastodon user:
Download the latest stable version of Mastodon:
Also install the Ruby and JavaScript dependencies:
Execute the Mastodon Setup Wizard:
You’ll now be asked about various settings, which will be saved in the .env.production
file at the end.
- Domain name: Enter the domain name of the VPS server
- Do you want to enable single user mode?: N
- Are you using Docker to run Mastodon?: N
- PostgreSQL host: default - Enter
- PostgreSQL port: default - Enter
- Name of PostgreSQL database: default - Enter
- Name of PostgreSQL user: default - Enter
- Password of PostgreSQL user: leer lassen - Enter
- Redis host: default - Enter
- Redis port: default - Enter
- Redis password: default – Enter
- Do you want to store uploaded files on the cloud?: N
- Do you want to send emails from localhost?: N
- SMTP server: Specify SMTP server
- SMTP port: Specify the port of the SMTP server
- SMTP username: User name for the login
- SMTP authentication: plain
- SMTP OpenSSL verify mode: none
- Email address to send emails “from”: mostly like SMTP-Login
- Send a test email with this configuration right now?: Y
- Send test email to: Enter any email address as recipient
- Save configuration?: Y
- Prepare the database now?: Y
- Compile the assets now?: Y
- Do you want to create an admin user straight away?: Y
- Username: admin
- Email: your email
Switch back to the root user:
Step 5: install SSL certificate
IONOS VPS servers come with an SSL certificate included by default. If your plan doesn’t include one, you can install it later.
For a free SSL certificate, consider Let’s Encrypt, which provides automated certificates that are easy to install and renew.
The certificate is saved in the folder /etc/letsencrypt/live/example.com/
on your Mastodon server.
Step 6: set up Nginx
You must copy the configuration template for Nginx from the Mastodon directory and paste it into the sites-available
directory of Nginx:
Create a symbolic link from the configuration file in sites-enabled
to enable it and remove the default configuration:
Launch the configuration file for your Mastodon server:
Enter your own domain name instead of example.com
.
Uncomment the lines ssl_certificate
and ssl_certificate_key
and replace the paths with those to your SSL certificate. If you use the default self-signing certificate, the paths remain unchanged:
Once you’ve adjusted the configuration, you must reload Nginx for the changes to take effect:
Step 7: set up systemd services
If you activate the Systemd services, the Mastodon web application and the real-time streaming functions are started automatically when the server is started. This ensures that your Mastodon server is permanently available.
Copy the Systemd service templates from Mastodon to the corresponding directory:
If you’ve changed any default values, verify that the username and paths in the service templates are correct.
Start and activate the Systemd services:
-
systemctl daemon-reload: Updates the configuration of systemd to reflect the new service templates.
-
systemctl enable –now mastodon-web mastodon-sidekiq mastodon-streaming: These services are responsible for the web application, background processing and real-time streaming functions of Mastodon.
Step 8: change character limit
Running your own Mastodon server gives you the flexibility to adjust settings not available on public servers. For instance, you can modify the character limit for posts, which is set to 500 characters by default but can be increased or decreased.
First, switch to the Mastodon user in the console. Then, edit two specific files.
Enter your desired value for the character limit in the following files:
compose_form.js
in directory~/live/app/javascript/mastodon/features/compose/components/
status_length_validator.rb
in~/live/app/validators/
In the file instance_serializer.rb
in the directory ~/live/app/serializers/rest/
, find the line containing :languages, :registrations,
and add :max_toot_chars,
after it.
In addition, add the following code under the line beginning with private
, inserting the desired value:
After you have made these changes, the Mastodon services must be restarted. This is done as the root user with the command:
Now you can write posts with a character limit of 1000 characters.
Step 9: moderation function
The moderation function under “Settings > Moderation” on your Mastodon server lets you, as an admin, monitor and manage content and user activity to ensure compliance with the Community Guidelines and remove unwanted content.
You can block, unblock, or delete individual accounts, domains, IP addresses, or email servers. Additionally, you can moderate user content by removing or editing inappropriate or offensive posts.
Try out your VPS for 30 days. If you're not satisfied, you get your money back.