How to Install Mastodon on OpenBSD
Mastodon is a free, decentralized, and open-source social media platform that enables users to create online communities. In this tutorial, we will walk you through the process of installing Mastodon on OpenBSD.
Prerequisites
Before you begin, make sure that your system meets the following requirements:
- OpenBSD 6.6 or later
- At least 2 GB of RAM
- A domain name that is pointed to your server's public IP address
- Basic knowledge of SSH and command-line interface
Step 1: Install Required Dependencies
Mastodon requires several dependencies to be installed on your OpenBSD system. The following command will install all necessary dependencies:
$ doas pkg_add node git libidn2 libffi postgresql-server postgresql-client redis mail smtpd nginx certbot
Step 2: Create a New User
It is recommended to create a new user on your system to run Mastodon. You can create a new user by running the following command:
$ doas adduser mastodon
Step 3: Install Mastodon
Download the latest version of Mastodon from the official repository using git. Change to the home directory of the new mastodon user, and clone the Mastodon repository:
$ su mastodon
$ git clone https://github.com/tootsuite/mastodon.git ~/live
$ cd ~/live
$ git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
$ bundle install --deployment --without development test
Step 4: Configure Mastodon
Mastodon requires a few configuration files to be created before it can be started. Use the following command to generate them:
$ RAILS_ENV=production SECRET_KEY_BASE=$(openssl rand -hex 64) bundle exec rails assets:precompile db:create db:migrate
Next, create a new environment file .env.production:
$ nano .env.production
Add the following lines to the file:
LOCAL_DOMAIN=your-domain.com
SECRET_KEY_BASE=$(openssl rand -hex 64)
OTP_SECRET=$(openssl rand -hex 64)
PAPERCLIP_SECRET=$(openssl rand -hex 64)
REDIS_PASSWORD=$(openssl rand -hex 64)
SMTP_SERVER=localhost
SMTP_PORT=25
SMTP_LOGIN=
SMTP_PASSWORD=
[email protected]
SMTP_DOMAIN=your-domain.com
SMTP_TLS=false
Make sure to replace your-domain.com with your actual domain name.
Step 5: Start Services
To start Mastodon, you need to start all of the necessary services. First, start the Postgres database:
$ doas rcctl start postgresql
Next, start the Redis service:
$ doas rcctl start redis
Now, create a new user for Mastodon:
$ RAILS_ENV=production bundle exec rails mastodon:create_user
You will need to enter a username, email address, and password for the new user.
Finally, start the Mastodon service:
$ RAILS_ENV=production bundle exec puma -C config/puma.rb
Step 6: Setup Nginx
Mastodon listens on port 3000 by default. To expose it to the internet via Nginx, create a new server block in the Nginx configuration file:
$ doas nano /etc/nginx/nginx.conf
Add the following server block:
server {
listen 80;
listen [::]:80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Also, create a new SSL certificate for your domain using certbot:
$ doas certbot certonly --webroot --agree-tos --no-eff-email --email [email protected] -w /var/www/acme -d your-domain.com
Now, open the Mastodon production configuration file:
$ doas nano .env.production
Add the following lines to the file:
LOCAL_DOMAIN=your-domain.com
WEB_DOMAIN=your-domain.com
STREAMING_CLUSTER_NUM=0
ACTIVE_STORAGE_CREDENTIALS=production
PAPERCLIP_EXPIRATION_POLICY=maximum
PAPERCLIP_URL_EXPIRATION_IN_MINUTES=60
ENABLE_COMPRESSION=true
RAILS_SERVE_STATIC_FILES=true
LOCAL_HTTPS=true
Save and close the file, then restart the Mastodon service:
$ killall -USR1 puma
You should now be able to access your Mastodon instance at https://your-domain.com.
Congratulations, you have successfully installed Mastodon on OpenBSD!