How to install Mastodon ActivityPub server on FreeBSD.
pkg install -y nginx acme.sh postgresql13-server mastodon
Add the following inside the http block of /usr/local/etc/nginx/nginx.conf
include /usr/local/www/mastodon/dist/nginx.conf;
Update Nginx configuration:
Note: The mastodon/dist/nginx.conf was originally provided by the www/mastodon package. It will need to be created.
sed -i '' -e 's/example.com/<YOUR DESIRED DOMAIN>/g' /usr/local/www/mastodon/dist/nginx.conf
Enable nginx on startup and start nginx:
sysrc nginx_enable="YES" service nginx start
mkdir -p /usr/local/etc/ssl/<YOUR DESIRED DOMAIN> acme.sh --issue --webroot /usr/local/www/mastodon/public -d <YOUR DESIRED DOMAIN> acme.sh --install-cert -d <YOUR DESIRED DOMAIN> --cert-file /usr/local/etc/ssl/<YOUR DESIRED DOMAIN>/cert.pem --key-file /usr/local/etc/ssl/<YOUR DESIRED DOMAIN>/key.pem --ca-file /usr/local/etc/ssl/<YOUR DESIRED DOMAIN>/ca.pem --fullchain-file /usr/local/etc/ssl/<YOUR DESIRED DOMAIN>/fullchain.pem --reloadcmd 'service nginx restart'
Enable postgresql on startup, initial databases and start postgresql:
sysrc postgresql_enable="YES" service postgresql initdb service postgresql start
Create a new role for the mastodon database:
su -l postgres -c 'createuser -d mastodon'
Enable redis on startup and start redis:
sysrc redis_enable="YES" service redis start
protected-mode should be disabled in /usr/local/etc/redis.conf
File permissions is an important factor for a working copy of Mastodon so let's switch to the dedicated mastodon user and run the installations:
su -l mastodon cd yarn set version classic bundle config deployment 'true' bundle config without 'development test' bundle install -j$(getconf _NPROCESSORS_ONLN) yarn install --pure-lockfile
On the next step let's install and configure the Mastodon system still as the mastodon user.
127.0.0.1 rather than localhost or sockets.
RAILS_ENV=production bundle exec rake mastodon:setup
Enable the services at startup and start the services:
sysrc mastodon_sidekiq_enable=YES sysrc mastodon_streaming_enable=YES sysrc mastodon_web_enable=YES service mastodon_sidekiq start service mastodon_streaming start service mastodon_web start
service mastodon_sidekiq stop service mastodon_streaming stop service mastodon_web stop
pkg upgrade -y
su -l mastodon cd bundle install -j$(getconf _NPROCESSORS_ONLN) yarn install --pure-lockfile RAILS_ENV=production bundle exec rails db:migrate RAILS_ENV=production bundle exec rake tmp:cache:clear RAILS_ENV=production bundle exec rails assets:precompile exit
service -R