15 C
Texas

Install Mastodon on Ubuntu 18.04 with Let’s Encrypt SSL Certificate

Mastodon is a free and Open Source self-hosted social community Server licensed underneath AGPLv3. Mastodon is comparable in features to Twitter and permits you to submit hyperlinks, text, video and snap shots and percentage inside the globally interconnected micro-blogging community. On this publish, we will discuss the way to deploy Mastodon on Ubuntu 18.04 Linux secured with Let’s Encrypt SSL Certificates.
Mastodon has a number of dependencies that need to be established. They include Ruby, PostgreSQL, Node.js, Yarn, Redis, Nginx e.t.c. Just follow the below steps to easily Install the Mastodon on your Ubuntu 18.04.

Salient Features of Mastodon

  • No vendor lock-in: Absolutely interoperable with any conforming platform
  • Real-time, chronological timeline updates: See the updates of human beings you’re following appear in real-time within the ui via WebSockets.
  • Safety and Moderation tols: Non-public posts, locked accounts, word filtering, muting, blocking off and all forms of different features, along with a reporting and moderation machine.
  • Media attachments like photos and quick movies: Upload and view photos and WebM/MP4 videos attached to the updates. Videos with no audio track are treated like GIFs; regular films are looped – like vines!
  • OAuth2 and a sincere REST API: Mastodon acts as an OAuth2 provider so 3rd party apps can use the REST and Streaming APIs, ensuing in a wealthy app environment with a number of alternatives!

Requirements

You’ll be required to have the below packages on Ubuntu 18.04.

  • PostgreSQL (minimum 9.5 or later)
  • Redis
  • Ruby (minimum 2.4 or later)
  • Node.js (minimum 8 or later)

Make sure you’ve the following already installed at your system.

  • A machine running on Ubuntu 18.04 Operating System.
  • Domain Name as it will be required for the Mastodon Server. For instance example.com or you can also use as social.example.com.
  • The third and last thing is the SMTP server for the purpose of e-mail delivery service.

Step 1: Update your System

As usual we do, update your system.

- Advertisement -
sudo apt -y update && sudo apt -y upgrade 

After it restart your system.

sudo reboot

Step 2: Install Node.js & Yarn

Type the following command to install the Node.js

curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
sudo apt-get install -y nodejs

Make sure that the installation is successful by checking the version.

nodejs --version

Now, install the yarn

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt -y install yarn

Step 3: Install Required Dependency packages

Fire the below command to get installed the required dependency packages which are to be needed for the installation of the Mastodon on Ubuntu 18.04.

Make sure that these packages are to be installed locally.

sudo 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 libgdbm5 libgdbm-dev nginx redis-server redis-tools certbot python-certbot-nginx yarn libidn11-dev libicu-dev libjemalloc-dev

Step 4: Install Ruby

First of all create a user for Mastodon which will be used for these operations. I recommend you to run Ruby with rbenv because it allows you to manage multiple versions without any difficulty.

sudo adduser --disabled-login mastodon
sudo su - mastodon

And then install the rbenv & rbenv-build

git clone https://github.com/rbenv/rbenv.git ~/.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 https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

Then install the proper Ruby version.

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

As the default gem version shipped with Ruby 2.6.0 that is incompatible with the latest bundler. So, we may need to update gem & install bundler.

gem update --system
gem install bundler --no-document
exit

Step 5: Installing PostgreSQL Database Server

Make sure you’ve installed PostgreSQL Database Server. If you don’t have installed already, just follow the below link to get it installed on your system.

How To Install PostgreSQL on Ubuntu 18.04

sudo -u postgres psql
CREATE USER mastodon CREATEDB:
\q

Step 6:Downloading & Installing Mastodon

As to download and set up the Mastodon, you’ve to switch from your default user to the Mastodon user we’ve created earlier.

After it run the following command to install mastodon on your system.

sudo apt -y install git
sudo su -mastodon

Now, clone the Mastodon code

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)

Then install the dependencies

gem install bundler:1.17.3
bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test
yarn install --pure-lockfile

Now, run the below command to generate a configuration.

RAILS_ENV=production bundle exec rake mastodon:setup

When asked for the information required, please fill them accordingly.

/home/mastodon/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/lib/bundler/rubygems_integration.rb:200: warning: constant Gem::ConfigMap is deprecated
Your instance is identified by its domain name. Changing it afterward will break things.
Domain name: example.com
Single user mode disables registrations and redirects the landing page to your public profile.
Do you want to enable single user mode? yes
Are you using Docker to run Mastodon? no
PostgreSQL host: /var/run/postgresql
PostgreSQL port: 5432
Name of PostgreSQL database: mastodon_production
Name of PostgreSQL user: mastodon
Password of PostgreSQL user:
Database configuration works! ?
Redis host: localhost
Redis port: 6379
Redis password:
Redis configuration works! ?
Do you want to store uploaded files on the cloud? No
Do you want to send e-mails from localhost? yes
E-mail address to send e-mails "from": Mastodon [email protected]
Send a test e-mail with this configuration right now? no
This configuration will be written to .env.production
Save configuration? Yes

And when prompt for the compiling of assets select yes.

Then agree to the admin account creation

Done!
All done! You can now power on the Mastodon server
Do you want to create an admin user straight away? Yes
Username: admin
E-mail: [email protected]
You can login with the password: 1b417e401f44c3db5d30f2f2f2a2328b
You can change your password once you login.

After all these steps upgrade the yarn by running

yarn upgrade

Step 7: Configuring Nginx

For the reverse proxy server, we’ll use Nginx for the Mastodon. Verify the status of nginx if it is in running condition

systemctl status nginx

From the Mastodon directory, copy the config template for nginx by the below command.

sudo cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon.conf

Set up the correct DNS for Mastodon.

sudo vim /etc/nginx/sites-available/mastodon.conf

When done, simply activate the config.

sudo ln -s /etc/nginx/sites-available/mastodon.conf /etc/nginx/sites-enabled/mastodon.conf
sudo systemctl restart nginx

Allow access through the firewall

sudo ufw allow 'Nginx Full'

By Using Let’s Encrypt SSL Certificate

Type the command given to use the Let’s Encrypt Certificate.

sudo certbot --nginx -d exmaple.com

Output:

You’ll see the similar output

sudo certbot --nginx -d social.osradar.com
$ sudo certbot --nginx -d social.osradar.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
(A)gree/(C)ancel: A
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for social.osradar.com
Waiting for verification…
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/mastodon.conf
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/mastodon.conf
Congratulations! You have successfully enabled
https://social.osradar.com

Note: Replace the example.com with your domain.

Step 8: Setting up systemd services

From the Mastodon directory, copy the systemd service template.

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

To Verify that the username & paths are properly configured, edit the following files.

/etc/systemd/system/mastodon-web.service
/etc/systemd/system/mastodon-sidekiq.service
/etc/systemd/system/mastodon-streaming.service

And then start & enable the systemd services

sudo systemctl daemon-reload
for i in web sidekiq streaming; do sudo systemctl enable mastodon-$i && sudo systemctl restart mastodon-$i; done

Verify the status that it is working properly.

for i in web sidekiq streaming; do sudo systemctl enable mastodon-$i && sudo systemctl restart mastodon-$i; done

Step 9: Mastodon Dashboard

Access the Mastodon dashboard by visiting the domain in your browser. You will see the following screen. Just click on the Login button.

how to install mastodon on ubuntu 18.04

On the next screen appear, provide email and password of admin to continue.

setup mastodon on ubuntu 18.04

Then a tutorial will appear, complete it to finish the setup of Mastodon.

mastodon on ubuntu
mastodon

So, this is how you can Install Mastodon on Ubuntu 18.04.

Congratulations! You’ve successfully installed Mastodon on Ubuntu 18.04 with Let’s Encrypt.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article