Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Install Mastadon on Ubuntu 16.04

Mastodon is a free and open source, fast-growing social network platform written in Ruby and JavaScript. It has features very similar to the widely popular Twitter, but it is a decentralized federation of a server running open source software. This way, there are no risks of a single company monopolizing users communication.

In this article, we will Install Mastodon on one of our Ubuntu 16.04 virtual servers.

Login to your server as user root

ssh root@IP_address

and start a screen session

screen -S mastodon

Update all packages installed on your server

apt-get update && apt-get upgrade

Run the following commands to install Redis server, node.js, and several other necessary packages

curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -
apt-get -y install curl redis-server redis-tools libpq-dev libxml2-dev ffmpeg libxslt1-dev nodejs imagemagick ffmpeg
npm install -g yarn

Mastodon uses a PostgreSQL database, so the next step is to install PostgreSQL server and the ident daemon

apt-get install postgresql
apt-get install pidentd
systemctl start pidentd

Once the PostgreSQL is installed, login to the server and create a new mastodon user

su postgres
psql
CREATE USER mastodon CREATEDB;
\q
exit

Make the following changes to the PostgreSQL configuration file, in order to make users be able to login without a password

sed -i '/^local.*postgres.*peer$/a host    all     all     127.0.0.1/32    ident' /etc/postgresql/9.?/main/pg_hba.conf

Restart PostgreSQL for the changes to take effect.

Mastodon is Ruby based application, so we have to install Ruby and all its dependencies on our Ubuntu server:

apt-get -y install bison build-essential autoconf libgdbm3 libssl-dev zlib1g-dev libncurses5-dev libffi-dev libreadline6-dev libgdbm-dev libyaml-dev

Create a new user ‘mastodon’

adduser --disabled-password --disabled-login mastodon

Use rbenv as the newly created user to install the needed Ruby versoin.

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

and install ruby-build:

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

After all necessary packages and dependencies are installed, install Ruby with rbenv:

rbenv install 2.4.1
rbenv global 2.4.1

If you closely followed the steps above, all dependencies necessary for running Mastodon are installed on your server and we can start the Mastodon installation. We will clone the latest release from GitHub

# git clone https://github.com/tootsuite/mastodon.git live

Cloning into 'live'...
remote: Counting objects: 30954, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 30954 (delta 0), reused 0 (delta 0), pack-reused 30951
Receiving objects: 100% (30954/30954), 35.98 MiB | 17.44 MiB/s, done.
Resolving deltas: 100% (18912/18912), done.
Checking connectivity... done.

cd live
git checkout $(git tag | tail -n 1)

Next, install Bundler for managing the dependencies

gem install bundler --no-ri

and start the Mastodon installation

bundle install --deployment --without development test
yarn install

Create a configuration file for Mastodon

cp .env.production.sample .env.production

And modify the following lines as follow:

vim .env.production

REDIS_HOST=localhost
DB_HOST=/var/run/postgresql
DB_USER=mastodon
DB_NAME=mastodon_production

# Federation
LOCAL_DOMAIN=domainname.com

Create cronjob for several tasks that need to be run daily

crontab -u mastodon -e

RAILS_ENV=production
@daily cd /home/mastodon/live && /home/mastodon/.rbenv/shims/bundle exec rake mastodon:daily

As user root, create the following systemd services for Mastodon:

Systemd configuration for the web workers

vim /etc/systemd/system/mastodon-web.service:

[Unit]
Description=mastodon-web
After=network.target

[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="RAILS_ENV=production"
Environment="PORT=3000"
ExecStart=/home/mastodon/.rbenv/shims/bundle exec puma -C config/puma.rb
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

Systemd configuration for the background workers

vim /etc/systemd/system/mastodon-sidekiq.service:

[Unit]
Description=mastodon-sidekiq
After=network.target

[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="RAILS_ENV=production"
Environment="DB_POOL=5"
ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

Systemd configuration file for the streaming API

vim /etc/systemd/system/mastodon-streaming.service

[Unit]
Description=mastodon-streaming
After=network.target

[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="NODE_ENV=production"
Environment="PORT=4000"
ExecStart=/usr/bin/npm run start
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

With these configuration files, you can easily start, stop and restart Mastodon.

For more information about this social network please visit their official GitHub repo.


Our fast, SSD Powered Virtual Servers are perfect for your Mastadon app. Sign up and start using a scalable virtual server.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply in the comments section below. Thanks.



This post first appeared on Virtual-Server.org Virtual Server, please read the originial post: here

Share the post

How to Install Mastadon on Ubuntu 16.04

×

Subscribe to Virtual-server.org Virtual Server

Get updates delivered right to your inbox!

Thank you for your subscription

×