Installing Mastodon

2023/08/15

Overview

Below are some notes I made while installing some Mastodon instances.

Note Deviations from primary mastodon install notes

Intro

Install mastodon (v4.1.5, current as of 27 July 2023) on cloud-based Ubuntu 22.04.

Generally followed install directions from above with some significant alterations, documented below.

Preliminaries

Install postfix or sendmail

create a mastodon user

Install nginx

Install certbot for Let’s Encrypt

Now start using main mastodon install docs more closely

Install some basic system utilities

Install External Repos

PostgreSQL

Postgress will be installed from this repo a bit later

install nodejs

curl -sL https://deb.nodesource.com/setup_16.x | bash -

Install More System Packages

Now will also install postgreSQL from the preferred repository

Run apt-get install -y nodejs to install Node.js 16.x and npm

You may also need development tools to build native addons:

  apt-get install gcc g++ make build-essential

Get some other files installed that will be needed later

apt-get install libidn-dev idn libpq-dev redis

To install the Yarn package manager, run:

 curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
 echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
 sudo apt-get update && sudo apt-get install yarn

Install Yarn

Install Ruby

Install key Ruby tools

NB

If no system openssl version was found, ensure openssl headers are installed (https://github.com/rbenv/ruby-build/wiki#suggested-build-environment):

Install Ruby

Stay in .rbenv directory (or be sure you are there) and run:

Install ruby’s bundler

Install PostgreSQL

apt-get install postgresql {done earlier}

Start PostgreSQL

Create a postgresql user for mastodon

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.

Install Mastodon

fetch the mastodon code

Use git to download the latest stable release of Mastodon:

Install dependencies

Ruby and JavaScript dependencies

Might get:

An error occurred while installing charlock_holmes (0.7.7), and Bundler cannot continue.

In once case I also had an issue with needing icu: “icu required (brew install icu4c or apt-get install libicu-dev)”

“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.”

Might also need to add redis

Run interactive setup wizard

This will:

The configuration file is saved as .env.production. You can review and edit it to your liking. Refer to the documentation on configuration.

the config wizard will run. remember your new admin username and temporary password

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

Setting up nginx

Deviation

This is where I had to make the most changes from the joinmastodon instructions. Ngnix as installed and configured out of the box wasn’t ready for running ssh. I needed to edit the basic nginx config to remove the ssh portion temporarily. Then ran certbot to get a Let’s Encrypt certificate for my site.

This needs to be done again and take closer notes.

Back to joinmastodon instructions

Copy the configuration template for nginx from the Mastodon directory:

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

Reload nginx for the changes to take effect:

Skip certificate instructions, since already did that

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:

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

Finally, start and enable the new systemd services:

They will now automatically start at boot. Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest Why you should do it regularly: https://github.com/browserslist/update-db#readme

Done!

tarting A high performance web server and a reverse proxy server… Jul 28 19:06:04 moth.orchids.social nginx[60318]: nginx: [emerg] no “ssl_certificate” is defined for the “listen … ssl” directive in /etc/nginx/sites-enabled/mastodon-orchid.conf:25

Jul 28 19:06:04 moth.orchids.social nginx[60318]: nginx: configuration file /etc/nginx/nginx.conf test failed

Jul 28 19:06:04 moth.orchids.social systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE

Jul 28 19:06:04 moth.orchids.social systemd[1]: nginx.service: Failed with result ’exit-code'.

Jul 28 19:06:04 moth.orchids.social systemd[1]: Failed to start A high performance web server and a reverse proxy server.

comment out the listen until get a cert

server {

listen 443 ssl http2;

listen [::]:443 ssl http2;

server_name moth.orchids.social;

then edit the server file to rejoin what certbot did with what should also be in for ssl

“/home/mastodon/live/public/” failed (13: Permission denied), client: 51.81.167.146, server: moth.orchids.social,

chmod ugo+wx mastodon/

install plocate is helpful

Need to fix this

ERROR: Missing RAILS_ENV environment variable, please set it to “production”, “development”, or “test”.