<\/span><\/h2>\nIn this step, we will add the required repositories to our system.<\/p>\n
To make sure that curl is installed on your system, run the command:<\/p>\n
apt install -y curl<\/pre>\nEnable the NodeSource repository with the following curl command:<\/p>\n
curl -sL https:\/\/deb.nodesource.com\/setup_8.x | bash -<\/pre>\nBy using the following commands we will import the repository\u2019s GPG key. After this, we will enable the Yarn APT repository:<\/p>\n
curl -sS https:\/\/dl.yarnpkg.com\/debian\/pubkey.gpg | apt-key add -\r\necho \"deb https:\/\/dl.yarnpkg.com\/debian\/ stable main\" | tee \/etc\/apt\/sources.list.d\/yarn.list<\/pre>\n<\/span>Step 2: Installing Packages<\/span><\/h2>\nNow we will install the required system packages for Mastodon:<\/p>\n
apt update\r\n\r\napt install -y \\\r\nimagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \\\r\ng++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf \\\r\nbison build-essential libssl-dev libyaml-dev libreadline6-dev \\\r\nzlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev \\\r\nnginx redis-server redis-tools postgresql postgresql-contrib \\\r\ncertbot yarn libidn11-dev libicu-dev libjemalloc-dev<\/pre>\nHere’s a brief explanation of the dependencies we just installed:<\/p>\n
\nimagemagick<\/strong> – Mastodon uses ImageMagick for image related operations<\/li>\nffmpeg<\/strong> – Mastodon uses FFmpeg for conversion of GIFs to MP4s<\/li>\nlibprotobuf-dev and protobuf-compiler<\/strong> – Mastodon uses these for language detection<\/li>\nnginx<\/strong> – Nginx is used as a web server<\/li>\nredis-*<\/strong> – Mastodon uses Redis for its in-memory data structure store<\/li>\npostgresql-*<\/strong> – Mastodon uses PostgreSQL as its SQL database<\/li>\nnodejs<\/strong> – Node is used for Mastodon’s streaming API<\/li>\nyarn<\/strong> – Yarn is a Node.js package manager<\/li>\nOther -dev packages, g++<\/strong> – these are needed for the compilation of Ruby using ruby-build.<\/li>\n<\/ul>\n<\/span>Step 3: Installing Ruby<\/span><\/h2>\nRuby is also one of the requirements for Mastodon and we will install it in this step. We will use ‘rbenv’ to manage the Ruby versions. But since rbenv needs to be installed for a specific Linux user, the first thing we need to do is create a new Mastodon user. To create the Mastodon user, we will execute the command:<\/p>\n
adduser --disabled-login mastodon<\/pre>\nThen switch to the user mastodon with the command:<\/p>\n
su - mastodon<\/pre>\nAnd with the following commands we will install rbenv and rbenv-build:<\/p>\n
git clone https:\/\/github.com\/rbenv\/rbenv.git ~\/.rbenv\r\ncd ~\/.rbenv && src\/configure && make -C src\r\necho 'export PATH=\"$HOME\/.rbenv\/bin:$PATH\"' >> ~\/.bashrc\r\necho 'eval \"$(rbenv init -)\"' >> ~\/.bashrc\r\nexec bash\r\ngit clone https:\/\/github.com\/rbenv\/ruby-build.git ~\/.rbenv\/plugins\/ruby-build<\/pre>\nAfter we finish the rbenv and rbenv-build installation, we can install the exact Ruby version we need:<\/p>\n
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.6.0\r\nrbenv global 2.6.0<\/pre>\nBecause ruby_2.6.0 comes with a bundler that is not compatible with the default gem version, we’ll need to update the gem:<\/p>\n
gem update --system<\/pre>\nOn top of this, we need to install bundler:<\/p>\n
gem install bundler --no-document<\/pre>\nOnce all of the steps have been processed, we can return to the root user:<\/p>\n
exit<\/pre>\n<\/span>Step 4: Setting up PostgreSQL<\/span><\/h2>\nWe will create a PostgreSQL user that can be used by the Linux user with the same username without requiring a separate password. This is a very simple method that uses the \u201cident\u201d authentication which allows for easy setup as well as allowing local users to access the database without a password.<\/p>\n
You can open the Postgres prompt by switching to the postgres user and then running the\u00a0psql<\/strong> command, or you can execute the following command:<\/p>\nsudo -u postgres psql<\/pre>\nExecute the command:<\/p>\n
CREATE USER mastodon CREATEDB;<\/pre>\nExit from the Postgres prompt with:<\/p>\n
\\q<\/pre>\n<\/span>Step 5: Setting up Mastodon<\/span><\/h2>\nSince we have prepared the server for installing Mastodon, we can proceed now with downloading the Mastodon code. Switch to the mastodon user with the command:<\/p>\n
su - mastodon<\/pre>\nWe will use git to clone the latest stable release of Mastodon by running the commands:<\/p>\n
git clone https:\/\/github.com\/tootsuite\/mastodon.git live && cd live\r\ngit checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)<\/pre>\n<\/span>Step 6: Installing the Ruby and JavaScript Dependencies<\/span><\/h2>\nThese are the last dependencies that we need to install. We will use bundler to install the rest of the Ruby dependencies:<\/p>\n
bundle install \\\r\n-j$(getconf _NPROCESSORS_ONLN) \\\r\n--deployment --without development test<\/pre>\nand use yarn to install Node.js dependencies:<\/p>\n
yarn install --pure-lockfile<\/pre>\n<\/span>Step 7: Generating a Configuration File<\/span><\/h2>\nWe can run the interactive setup wizard in order to generate the configuration file:<\/p>\n
RAILS_ENV=production bundle exec rake mastodon:setup<\/pre>\nNow we can switch back to the root account because that is all we had to do with the mastodon user.<\/p>\n
exit<\/pre>\n<\/span>Step 8: Setting up Nginx<\/span><\/h2>\nMastodon comes by default with an Nginx configuration template. In the next step, we will use a copy of this configuration template and adjust it for our needs.<\/p>\n
cp \/home\/mastodon\/live\/dist\/nginx.conf \/etc\/nginx\/sites-available\/mastodon.conf\r\nln -s \/etc\/nginx\/sites-available\/mastodon.conf \/etc\/nginx\/sites-enabled\/mastodon.conf<\/pre>\nThen edit \/etc\/nginx\/sites-available\/mastodon.conf<\/code> and replace your_domain.com<\/span> with your actual domain name.<\/p>\nnano \/etc\/nginx\/sites-available\/mastodon.conf<\/pre>\nWe need to reload Nginx for the changes to take effect:<\/p>\n
systemctl reload nginx<\/pre>\nIf for some reason you accidentally lack the Nginx file in that location, then you can use the following Nginx configuration and modify it according to your needs.<\/p>\n
map $http_upgrade $connection_upgrade {\r\ndefault upgrade;\r\n'' close;\r\n}\r\n\r\nproxy_cache_path \/var\/cache\/nginx levels=1:2 keys_zone=CACHE:10m inactive=7d max_size=1g;\r\n\r\nserver {\r\nlisten 80;\r\nlisten [::]:80;\r\nserver_name your_domain.com<\/span>;\r\nroot \/home\/mastodon\/live\/public;\r\nlocation \/.well-known\/acme-challenge\/ { allow all; }\r\nlocation \/ { return 301 https:\/\/$host$request_uri; }\r\n}\r\n\r\nserver {\r\nlisten 443 ssl http2;\r\nlisten [::]:443 ssl http2;\r\nserver_name your_domain.com<\/span>;\r\n\r\nssl_protocols TLSv1.2;\r\nssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;\r\nssl_prefer_server_ciphers on;\r\nssl_session_cache shared:SSL:10m;\r\n\r\n# Uncomment these lines once you acquire a certificate:\r\n# ssl_certificate \/etc\/letsencrypt\/live\/your_domain.com<\/span>\/fullchain.pem;\r\n# ssl_certificate_key \/etc\/letsencrypt\/live\/your_domain.com<\/span>\/privkey.pem;\r\n\r\nkeepalive_timeout 70;\r\nsendfile on;\r\nclient_max_body_size 80m;\r\n\r\nroot \/home\/mastodon\/live\/public;\r\n\r\ngzip on;\r\ngzip_disable \"msie6\";\r\ngzip_vary on;\r\ngzip_proxied any;\r\ngzip_comp_level 6;\r\ngzip_buffers 16 8k;\r\ngzip_http_version 1.1;\r\ngzip_types text\/plain text\/css application\/json application\/javascript text\/xml application\/xml application\/xml+rss text\/javascript;\r\n\r\nadd_header Strict-Transport-Security \"max-age=31536000\";\r\n\r\nlocation \/ {\r\ntry_files $uri @proxy;\r\n}\r\n\r\nlocation ~ ^\/(emoji|packs|system\/accounts\/avatars|system\/media_attachments\/files) {\r\nadd_header Cache-Control \"public, max-age=31536000, immutable\";\r\nadd_header Strict-Transport-Security \"max-age=31536000\";\r\ntry_files $uri @proxy;\r\n}\r\n\r\nlocation \/sw.js {\r\nadd_header Cache-Control \"public, max-age=0\";\r\nadd_header Strict-Transport-Security \"max-age=31536000\";\r\ntry_files $uri @proxy;\r\n}\r\n\r\nlocation @proxy {\r\nproxy_set_header Host $host;\r\nproxy_set_header X-Real-IP $remote_addr;\r\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\nproxy_set_header X-Forwarded-Proto https;\r\nproxy_set_header Proxy \"\";\r\nproxy_pass_header Server;\r\n\r\nproxy_pass http:\/\/127.0.0.1:3000;\r\nproxy_buffering on;\r\nproxy_redirect off;\r\nproxy_http_version 1.1;\r\nproxy_set_header Upgrade $http_upgrade;\r\nproxy_set_header Connection $connection_upgrade;\r\n\r\nproxy_cache CACHE;\r\nproxy_cache_valid 200 7d;\r\nproxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;\r\nadd_header X-Cached $upstream_cache_status;\r\nadd_header Strict-Transport-Security \"max-age=31536000\";\r\n\r\ntcp_nodelay on;\r\n}\r\n\r\nlocation \/api\/v1\/streaming {\r\nproxy_set_header Host $host;\r\nproxy_set_header X-Real-IP $remote_addr;\r\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\nproxy_set_header X-Forwarded-Proto https;\r\nproxy_set_header Proxy \"\";\r\n\r\nproxy_pass http:\/\/127.0.0.1:4000;\r\nproxy_buffering off;\r\nproxy_redirect off;\r\nproxy_http_version 1.1;\r\nproxy_set_header Upgrade $http_upgrade;\r\nproxy_set_header Connection $connection_upgrade;\r\n\r\ntcp_nodelay on;\r\n}\r\n\r\nerror_page 500 501 502 503 504 \/500.html;\r\n}<\/pre>\nRemember to save and exit the file, and restart Nginx as shown above in order to acknowledge the new file.<\/p>\n
<\/span>Step 9: Acquiring an SSL Certificate<\/span><\/h2>\nWe will use Let’s Encrypt to generate a free SSL certificate:<\/p>\n
certbot certonly --webroot -d your_domain.com<\/span> -w \/home\/mastodon\/live\/public\/<\/pre>\nPlease do not forget to replace your_domain.com<\/span> with your actual domain name. We can now edit the\u00a0\/etc\/nginx\/sites-available\/mastodon.conf<\/code> configuration file with:<\/p>\nnano \/etc\/nginx\/sites-available\/mastodon.conf<\/pre>\nUncomment and modify the ssl_certificate<\/strong> and ssl_certificate_key<\/strong> lines. Once we finish editing the configuration file, we need to reload Nginx once again for our changes to have effect:<\/p>\nsystemctl reload nginx<\/pre>\nAt this point, if you try to access your domain in your preferred web browser, you will not be able to see Mastodon. This is because our Mastodon process is not yet started.<\/p>\n
<\/span>Step 10: Setting up systemd Services<\/span><\/h2>\nIn this step, we will start and enable the Mastodon service on the server. We can simply copy the systemd service templates from the Mastodon directory:<\/p>\n
cp \/home\/mastodon\/live\/dist\/mastodon-*.service \/etc\/systemd\/system\/<\/pre>\nWe can double check and make sure that the username and paths are correct in these files:<\/p>\n
\n\/etc\/systemd\/system\/mastodon-web.service<\/code><\/li>\n\/etc\/systemd\/system\/mastodon-sidekiq.service<\/code><\/li>\n\/etc\/systemd\/system\/mastodon-streaming.service<\/code><\/li>\n<\/ul>\nFinally, we can start and enable the Mastodon systemd services:<\/p>\n
systemctl start mastodon-web mastodon-sidekiq mastodon-streaming\r\nsystemctl enable mastodon-web mastodon-sidekiq mastodon-streaming<\/pre>\nIf the systemd files are missing by any chance you can use the following configurations. You need to create three systemd Mastodon service files.<\/p>\n
For the Mastodon web workers service enter the following:<\/p>\n
nano \/etc\/systemd\/system\/mastodon-web.service<\/pre>\nPlace the following code:<\/p>\n
[Unit]\r\nDescription=mastodon-web\r\nAfter=network.target\r\n\r\n[Service]\r\nType=simple\r\nUser=mastodon\r\nWorkingDirectory=\/home\/mastodon\/live\r\nEnvironment=\"RAILS_ENV=production\"\r\nEnvironment=\"PORT=3000\"\r\nExecStart=\/home\/mastodon\/.rbenv\/shims\/bundle exec puma -C config\/puma.rb\r\nExecReload=\/bin\/kill -SIGUSR1 $MAINPID\r\nTimeoutSec=15\r\nRestart=always\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\nThen save and exit.<\/p>\n
For the Mastodon background queue service:<\/p>\n
nano \/etc\/systemd\/system\/mastodon-sidekiq.service<\/pre>\nPaste the following code:<\/p>\n
[Unit]\r\nDescription=mastodon-sidekiq\r\nAfter=network.target\r\n\r\n[Service]\r\nType=simple\r\nUser=mastodon\r\nWorkingDirectory=\/home\/mastodon\/live\r\nEnvironment=\"RAILS_ENV=production\"\r\nEnvironment=\"DB_POOL=25\"\r\nEnvironment=\"MALLOC_ARENA_MAX=2\"\r\nExecStart=\/home\/mastodon\/.rbenv\/shims\/bundle exec sidekiq -c 25\r\nTimeoutSec=15\r\nRestart=always\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\nThen save and exit the file.<\/p>\n
For the Mastodon streaming API service:<\/p>\n
nano \/etc\/systemd\/system\/mastodon-streaming.service<\/pre>\nPlace the following code:<\/p>\n
[Unit]\r\nDescription=mastodon-streaming\r\nAfter=network.target\r\n\r\n[Service]\r\nType=simple\r\nUser=mastodon\r\nWorkingDirectory=\/home\/mastodon\/live\r\nEnvironment=\"NODE_ENV=production\"\r\nEnvironment=\"PORT=4000\"\r\nEnvironment=\"STREAMING_CLUSTER_NUM=1\"\r\nExecStart=\/usr\/bin\/node .\/streaming\r\nTimeoutSec=15\r\nRestart=always\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\nSave and exit.<\/p>\n
You’ll need to reload the systemctl daemon list for the changes to take effect:<\/p>\n
systemctl daemon-reload<\/pre>\nYou should now be able to start and enable the Mastodon systemd services as we did earlier.<\/p>\n
Congratulations! You have successfully installed Mastodon on your server. You can access it by going to https:\/\/your_domain.com\/<\/span>.<\/p>\nIn this article, we showed you how to install Mastodon on Ubuntu 18.04. Now you can use this knowledge and create your private social network with this wonderful application.<\/p>\n
\n Of course, if you are one of our Managed Ubuntu Hosting<\/a> customers, you don\u2019t have to install Mastodon on your Ubuntu 18.04 VPS \u2013 simply ask our admins, sit back, and relax. Our admins will install Mastodon on Ubuntu 18.04 for you immediately.<\/p>\nPS.<\/strong><\/span> If you liked this post on how to install Mastodon on an Ubuntu 18.04 VPS, please share it with your friends on the social networks using the buttons below, or simply leave a comment in the comments section. Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"In this article, we will install Mastodon on an Ubuntu 18.04 VPS. Mastodon is a free and open-source network platform … <\/p>\n
Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":31934,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,1698],"tags":[],"yoast_head":"\nHow to Install Mastodon on Ubuntu 18.04 - RoseHosting<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n \n \n\t \n\t \n\t \n