ssh userame@IP_Address<\/pre>\nOnce you are logged in, issue the following commands to make sure all installed packages are up to date:<\/p>\n
sudo yum update<\/pre>\nNext, install the install the pre-requisite packages necessary for building Mastodon with the following command:<\/p>\n
sudo yum install curl git gpg gcc git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make autoconf automake libtool bison curl sqlite-devel ImageMagick libxml2-devel libxslt-devel gdbm-devel ncurses-devel glibc-headers glibc-devel libicu-devel libidn-devel protobuf-devel protobuf<\/pre>\n<\/span>2. Install Node.js and Yarn<\/span><\/h2>\nWe will install Node.js v8 LTS from the NodeSource repository which depends on the EPEL repository being enabled.<\/p>\n
To enable the EPEL repository on your CentOS 7 VPS, issue the following command:<\/p>\n
sudo yum install epel-release curl<\/pre>\nOnce the EPEL repository is enabled run the following command to add the Node.js v8 LTS repository:<\/p>\n
curl --silent --location https:\/\/rpm.nodesource.com\/setup_8.x | sudo bash -<\/pre>\nOnce the NodeSource repository is enabled install the Node.js with the following command:<\/p>\n
sudo yum install nodejs<\/pre>\nEnable the Yarn RPM repository with:<\/p>\n
curl --silent --location https:\/\/dl.yarnpkg.com\/rpm\/yarn.repo | sudo tee \/etc\/yum.repos.d\/yarn.repo<\/pre>\nInstall the latest Yarn version with:<\/p>\n
sudo yum install yarn<\/pre>\n<\/span>3. Install PostgreSQL<\/span><\/h2>\nEnable the PostgreSQL repository:<\/p>\n
sudo rpm -Uvh https:\/\/download.postgresql.org\/pub\/repos\/yum\/9.6\/redhat\/rhel-7-x86_64\/pgdg-centos96-9.6-3.noarch.rpm\r\n<\/pre>\nTo install the PostgreSQL server run the following command:<\/p>\n
sudo yum install postgresql96-server postgresql96-contrib postgresql96-devel<\/pre>\nOnce the installation is completed, create a new database cluster with:<\/p>\n
sudo \/usr\/pgsql-9.6\/bin\/postgresql96-setup initdb<\/pre>\nStart the PostgreSQL service and enable it to start on boot:<\/p>\n
sudo systemctl enable postgresql-9.6\r\nsudo systemctl start postgresql-9.6<\/pre>\nLogin to the PostgreSQL shell:<\/p>\n
sudo -u postgres psql<\/pre>\nCreate a new user for the Mastodon instance:<\/p>\n
CREATE USER mastodon CREATEDB;<\/pre>\n<\/span>4. Install Redis<\/span><\/h2>\nInstalling Redis is pretty straightforward, just run the following command:<\/p>\n
sudo yum install redis<\/pre>\n<\/span>5. Create a new system user<\/span><\/h2>\nTo create a new system user for Mastodon run the following command:<\/p>\n
sudo adduser mastodon<\/pre>\n<\/span>6. Install Ruby<\/span><\/h2>\nWe will install Ruby using the Rbenv script.<\/p>\n
Before cloning the rbenv repository switch to the new mastodon user:<\/p>\n
sudo su - mastodon<\/pre>\nSet up rbenv and ruby-build with the following commands:<\/p>\n
cd\r\ngit clone git:\/\/github.com\/sstephenson\/rbenv.git .rbenv\r\necho 'export PATH=\"$HOME\/.rbenv\/bin:$PATH\"' >> ~\/.bash_profile\r\necho 'eval \"$(rbenv init -)\"' >> ~\/.bash_profile\r\nexec $SHELL\r\n\r\ngit clone git:\/\/github.com\/sstephenson\/ruby-build.git ~\/.rbenv\/plugins\/ruby-build\r\necho 'export PATH=\"$HOME\/.rbenv\/plugins\/ruby-build\/bin:$PATH\"' >> ~\/.bash_profile\r\nexec $SHELL\r\n<\/pre>\nOnce both rbenv and ruby-build are setups, install the latest Ruby version with”<\/p>\n
rbenv install 2.5.1\r\nrbenv global 2.5.1\r\n<\/pre>\nTo verify everything is done correctly, use the command ruby --version<\/code>.<\/p>\nThe output should be similar to the following:<\/p>\n
ruby --version\r\nruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]\r\n<\/pre>\n<\/span>7. Clone the Mastodon git repository and install dependencies<\/span><\/h2>\nThe following commands are also run as mastodon user.<\/p>\n
Clone the mastodon git repository into the ~\/live<\/code> directory and checkout to the latest stable Mastodon branch:<\/p>\ncd\r\ngit clone https:\/\/github.com\/tootsuite\/mastodon.git live\r\ncd ~\/live\r\ngit checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)\r\n<\/pre>\nInstall bundler and ruby dependencies with the following commands:<\/p>\n
gem install bundler\r\nbundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test\r\n<\/pre>\nInstall the node.js dependencies with:<\/p>\n
yarn install --pure-lockfile\r\n<\/pre>\n<\/span>8. Configure Mastodon<\/span><\/h2>\nThe following commands are run as mastodon user.<\/p>\n
Change to the Mastodon installation directory and run the following command to start the setup:<\/p>\n
cd ~\/live\r\nRAILS_ENV=production bundle exec rake mastodon:setup\r\n<\/pre>\nThe installer will ask you several questions, generate new app secret, set up the database schema and compile the assets.<\/p>\n
Your instance is identified by its domain name. Changing it afterward will break things.\r\nDomain name: your-domain.com\r\n\r\nSingle user mode disables registrations and redirects the landing page to your public profile.\r\nDo you want to enable single user mode? No\r\n\r\nAre you using Docker to run Mastodon? no\r\n\r\nPostgreSQL host: \/var\/run\/postgresql\r\nPostgreSQL port: 5432\r\nName of PostgreSQL database: mastodon_production\r\nName of PostgreSQL user: mastodon\r\nPassword of PostgreSQL user:\r\nDatabase configuration works! 🎆\r\n\r\nRedis host: localhost\r\nRedis port: 6379\r\nRedis password:\r\nRedis configuration works! 🎆\r\n\r\nDo you want to store uploaded files on the cloud? No\r\n\r\nDo you want to send e-mails from localhost? yes\r\nE-mail address to send e-mails \"from\": Mastodon <notifications@your-domain.com>\r\nSend a test e-mail with this configuration right now? no\r\n\r\nThis configuration will be written to .env.production\r\nSave configuration? Yes\r\n\r\nNow that configuration is saved, the database schema must be loaded.\r\nIf the database already exists, this will erase its contents.\r\nPrepare the database now? Yes\r\nRunning `RAILS_ENV=production rails db:setup` ...\r\n\r\n\r\nCreated database 'mastodon_production'\r\n\r\n...\r\n\r\nDone!\r\n\r\nThe final step is compiling CSS\/JS assets.\r\nThis may take a while and consume a lot of RAM.\r\nCompile the assets now? Yes\r\nRunning `RAILS_ENV=production rails assets:precompile` ...\r\n\r\n\r\nyarn install v1.9.4\r\n\r\n...\r\n\r\nUsing \/home\/mastodon\/live\/config\/webpacker.yml file for setting up webpack paths\r\nCompiling\u2026\r\n Compiled all packs in \/home\/mastodon\/live\/public\/packs\r\n Rendering errors\/500.html.haml within layouts\/error\r\n Rendered errors\/500.html.haml within layouts\/error (2596.9ms)\r\nDone!\r\n\r\nAll done! You can now power on the Mastodon server 🐘\r\n\r\nDo you want to create an admin user straight away? Yes\r\nUsername: admin\r\nE-mail: admin@your-domain.com\r\nYou can login with the password: 80b4aA233adaeS86d095Scbf79302f81\r\nYou can change your password once you login.\r\n<\/pre>\n<\/span>9. Create Mastodon systemd units<\/span><\/h2>\nThe following commands are run as root or sudo user.<\/p>\n
Open your text editor and create the following systemd unit files:<\/p>\n
sudo nano \/etc\/systemd\/system\/mastodon-web.service<\/pre>\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\r\n<\/pre>\nsudo nano \/etc\/systemd\/system\/mastodon-sidekiq.service<\/pre>\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=5\"\r\nExecStart=\/home\/mastodon\/.rbenv\/shims\/bundle exec sidekiq -c 5 -q default -q push -q mailers -q pull\r\nTimeoutSec=15\r\nRestart=always\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\nsudo nano \/etc\/systemd\/system\/mastodon-streaming.service<\/pre>\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\nExecStart=\/usr\/bin\/npm run start\r\nTimeoutSec=15\r\nRestart=always\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\nEnable and start all services:<\/p>\n
sudo systemctl enable mastodon-web.service\r\nsudo systemctl enable mastodon-sidekiq.service\r\nsudo systemctl enable mastodon-streaming.service\r\n\r\nsudo systemctl start mastodon-web.service\r\nsudo systemctl start mastodon-sidekiq.service\r\nsudo systemctl start mastodon-streaming.service\r\n<\/pre>\n<\/span>10. Install and configure Nginx<\/span><\/h2>\nTo install Nginx run the following command:<\/p>\n
sudo yum install nginx\r\n<\/pre>\nOnce nginx is installed, create a server block for your domain. Do not forget to set the correct path to the SSL certificate and private key.<\/p>\n
sudo nano \/etc\/nginx\/conf.d\/your-domain.com.conf\r\n<\/pre>\nmap $http_upgrade $connection_upgrade {\r\n default upgrade;\r\n '' close;\r\n}\r\n\r\nserver {\r\n listen 80;\r\n listen [::]:80;\r\n server_name your-domain.com;\r\n root \/home\/mastodon\/live\/public;\r\n # Useful for Let's Encrypt\r\n location \/.well-known\/acme-challenge\/ { allow all; }\r\n location \/ { return 301 https:\/\/$host$request_uri; }\r\n}\r\n\r\nserver {\r\n listen 443 ssl http2;\r\n listen [::]:443 ssl http2;\r\n server_name your-domain.com;\r\n\r\n ssl_protocols TLSv1.2;\r\n ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;\r\n ssl_prefer_server_ciphers on;\r\n ssl_session_cache shared:SSL:10m;\r\n\r\n ssl_certificate \/etc\/ssl\/certs\/certificate.crt;\r\n ssl_certificate_key \/etc\/ssl\/private\/certificate.key;\r\n\r\n keepalive_timeout 70;\r\n sendfile on;\r\n client_max_body_size 80m;\r\n\r\n root \/home\/mastodon\/live\/public;\r\n\r\n gzip on;\r\n gzip_disable \"msie6\";\r\n gzip_vary on;\r\n gzip_proxied any;\r\n gzip_comp_level 6;\r\n gzip_buffers 16 8k;\r\n gzip_http_version 1.1;\r\n gzip_types text\/plain text\/css application\/json application\/javascript text\/xml application\/xml application\/xml+rss text\/javascript;\r\n\r\n add_header Strict-Transport-Security \"max-age=31536000\";\r\n\r\n location \/ {\r\n try_files $uri @proxy;\r\n }\r\n\r\n location ~ ^\/(emoji|packs|system\/accounts\/avatars|system\/media_attachments\/files) {\r\n add_header Cache-Control \"public, max-age=31536000, immutable\";\r\n try_files $uri @proxy;\r\n }\r\n \r\n location \/sw.js {\r\n add_header Cache-Control \"public, max-age=0\";\r\n try_files $uri @proxy;\r\n }\r\n\r\n location @proxy {\r\n proxy_set_header Host $host;\r\n proxy_set_header X-Real-IP $remote_addr;\r\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n proxy_set_header X-Forwarded-Proto https;\r\n proxy_set_header Proxy \"\";\r\n proxy_pass_header Server;\r\n\r\n proxy_pass http:\/\/127.0.0.1:3000;\r\n proxy_buffering off;\r\n proxy_redirect off;\r\n proxy_http_version 1.1;\r\n proxy_set_header Upgrade $http_upgrade;\r\n proxy_set_header Connection $connection_upgrade;\r\n\r\n tcp_nodelay on;\r\n }\r\n\r\n location \/api\/v1\/streaming {\r\n proxy_set_header Host $host;\r\n proxy_set_header X-Real-IP $remote_addr;\r\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n proxy_set_header X-Forwarded-Proto https;\r\n proxy_set_header Proxy \"\";\r\n\r\n proxy_pass http:\/\/127.0.0.1:4000;\r\n proxy_buffering off;\r\n proxy_redirect off;\r\n proxy_http_version 1.1;\r\n proxy_set_header Upgrade $http_upgrade;\r\n proxy_set_header Connection $connection_upgrade;\r\n\r\n tcp_nodelay on;\r\n }\r\n\r\n error_page 500 501 502 503 504 \/500.html;\r\n}\r\n<\/pre>\nSave the file and restart the nginx service:<\/p>\n
sudo systemctl restart nginx\r\n<\/pre>\nYou can now open your browser, type your domain and you will be presented with the Mastodon login form.<\/p>\n
<\/p>\n
<\/p>\n
\n Of course, you don\u2019t have to install Mastodon on CentOS 7,\u00a0if you use one of our managed hosting services<\/a>, in which case you can simply ask our expert Linux admins to install Mastodon for you. They are available 24×7 and will take care of your request immediately.<\/p>\nPS<\/strong><\/span>. If you liked this post, on\u00a0How to Install Mastodon on CentOS 7<\/strong> please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"Mastodon is an open-source free social network based on open web protocol. It used Ruby on Rails for the back-end … <\/p>\n
Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":28409,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1699],"tags":[34,1753],"yoast_head":"\nHow to install Mastodon on CentOS 7 - 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