How to Install and Configure Diaspora on Alibaba Cloud

Prerequisites

  1. You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get a free account in your Alibaba Cloud account. If you don’t know about how to setup your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1.5GB RAM and 2 Core processor.
  2. A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  3. Domain name must be pointed to your Alibaba Cloud ECS’s IP address
  4. Access to VNC console in your Alibaba Cloud or SSH client installed in your PC
  5. Set up your server’s hostname and create user with root privileges.

Setting Up Your Server

Before proceeding with installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with sudo privileges.

# sudo apt update && sudo apt upgrade
# sudo apt-get install build-essential
# sudo apt-get install libssl-dev
# sudo apt-get install libcurl4-openssl-dev
# sudo apt-get install libxml2-dev
# sudo apt-get install libxslt-dev
# sudo apt-get install imagemagick
# sudo apt-get install ghostscript
# sudo apt-get install curl
# sudo apt-get install libmagickwand-dev
# sudo apt-get install git
# git config --global user.name "Aareez"
# git config --global user.email "xyz@example.com"
# sudo apt-get install libpq-dev
# sudo apt-get install autoconf
# sudo apt-get install bison
# sudo apt-get install libyaml-dev
# sudo apt-get install libreadline6-dev
# sudo apt-get install zlib1g-dev
# sudo apt-get install libncurses5-dev
# sudo apt-get install libffi-dev
# sudo apt-get install libgdbm3
# sudo apt-get install libreadline-dev
# sudo apt-get install libgdbm-dev
# sudo apt-get install redis-server
# sudo apt-get install patch
# sudo apt-get install ruby-dev
# sudo apt-get install liblzma-dev

Install Node.js

Node.js is a cross platform open source JS runtime environment that runs JS code outside the browser. A version of Node.js is available in Ubuntu’s default repository. To install Node.js follow the steps below.

# sudo apt-get install nodejs

Install PostgreSQL Database

Diaspora supports PostgreSQL, MySQL and MariaDB. In this tutorial, I will use PostgreSQL.

# sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
# wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
# sudo apt-get -y install postgresql postgresql-contrib
# sudo systemctl start postgresql
# sudo systemctl enable postgresql
# sudo -u postgres psql
CREATE USER dias WITH CREATEDB PASSWORD '654321Ab';

Install Exim4

To send emails to use, you will need Exim4 as STMP relay. To install Exim4, execute the command below.

# sudo apt-get install exim4
# sudo dpkg-reconfigure exim4-config

Install Ruby

To install Ruby, you will use rbenv to manage environment and versions. Execute the following commands to download rbenv and set paths.

# git clone https://github.com/rbenv/rbenv.git ~/.rbenv
# cd ~/.rbenv && src/configure && make -C src
# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
# echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# sudo apt install rbenv
# rbenv install 2.4.3
# rbenv global 2.4.3

Install and Configure Diaspora

To install and configure Diaspora, follow the steps below.

# cd ~
# git clone -b master https://github.com/diaspora/diaspora.git
# cd diaspora
# cp config/database.yml.example config/database.yml
# cp config/diaspora.yml.example config/diaspora.yml
# sudo nano config/database.yml
# sudo nano config/diaspora.yml
  1. Set public facing url
  2. Uncomment by removing # from start of certificate_authorities
  3. Set value of rails_environment from development to production.
  4. Change require_ssl value from true to false.
  5. Uncomment listen: ‘http://localhost:3000'

Install Gems

Edit .ruby-version file and change value from 2.4 to 2.4.3.

# sudo nano .ruby-version
# sudo gem install bundler
# sudo script/configure_bundler
# sudo bin/bundle install --full-index

Setup Database

Now create and configure database by executing command below.

# RAILS_ENV=production bin/rake db:create db:migrate

Precompile Assets

To precompile the assets, execute the command below.

# RAILS_ENV=production bin/rake assets:precompile

Diaspora systemd Services

We will manage Diaspora via service. First of all, create the following files: target file, web service file, and sidekiq service file.

# sudo touch /etc/systemd/system/diaspora.target
# sudo touch /etc/systemd/system/diaspora-web.service
# sudo touch /etc/systemd/system/diaspora-sidekiq.service
# sudo nano /etc/systemd/system/diaspora.target[Unit]
Description=Diaspora social network
Wants=postgresql.service
Wants=redis-server.service
After=redis-server.service
After=postgresql.service
[Install]
WantedBy=multi-user.target
# sudo nano /etc/systemd/system/diaspora-web.service[Unit]
Description=Diaspora social network (unicorn)
PartOf=diaspora.target
StopWhenUnneeded=true
[Service]
User=diaspora
Environment=RAILS_ENV=production
WorkingDirectory=/home/aareez/diaspora
ExecStart=/bin/bash -lc "bin/bundle exec unicorn -c config/unicorn.rb -E production"
Restart=always
[Install]
WantedBy=diaspora.target
# sudo nano /etc/systemd/system/diaspora-sidekiq.service[Unit]
Description=Diaspora social network (sidekiq)
PartOf=diaspora.target
StopWhenUnneeded=true
[Service]
User=diaspora
Environment=RAILS_ENV=production
WorkingDirectory=/home/aareez/diaspora
ExecStart=/bin/bash -lc "bin/bundle exec sidekiq"
Restart=always
[Install]
WantedBy=diaspora.target
# sudo systemctl enable diaspora.target diaspora-sidekiq.service diaspora-web.service
# sudo systemctl restart diaspora.target
# sudo systemctl restart diaspora-sidekiq.service
# sudo systemctl restart diaspora-web.service

Install openSSL 1.1.0f

By default, openssl v1.0.2 is installed. But in your Nginx configuration file, you will use ssl_ecdh_curve which requires openssl 1.1.0f or higher, otherwise you will get syntax error. To install openssl, execute the following set of commands.

# cd ~
# wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz
# tar -xf openssl-1.1.0f.tar.gz
# cd openssl-1.1.0f
# ./config -Wl,--enable-new-dtags,-rpath,'$(LIBRPATH)'
# sudo make
# sudo make install
# openssl version

Install Apache Server

You will be required to install apache server, for this purpose, you will need to follow the steps below.

# sudo apt-get install apache2
# sudo systemctl start apache2
# sudo systemctl status apache2

Install Let’s Encrypt SSL Certificate

Certbot will require port 80 for obtaining new certificate. Hence, in the first step, you will need to stop apache server because apache uses port 80. To do so, execute the command.

# sudo systemctl stop apache2
# sudo apt-get update
# sudo apt-get install software-properties-common
# sudo add-apt-repository ppa:certbot/certbot
# sudo apt-get update
# sudo apt-get install python-certbot-apache
# sudo certbot certonly --standalone --register-unsafely-without-email -d softpedia.xyz
# openssl dhparam -out /home/aareez/.acme.sh/softpedia.xyz_ecc/dhparam.pem 2048
# sudo nano /etc/apache2/sites-available/diaspora.conf
<VirtualHost *:80>
ServerName softpedia.xyz
ServerAlias www.softpedia.xyz

RedirectPermanent / https://softpedia.xyz/
</VirtualHost>
<VirtualHost *:443>
ServerName softpedia.xyz
ServerAlias www.softpedia.xyz

DocumentRoot /home/aareez/diaspora/public
RewriteEngine On RewriteCond %{HTTP_HOST} !^softpedia\.xyz [NC]
RewriteRule ^/(.*)$ https://softpedia\.xyz/$1 [L,R,QSA]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://upstream%{REQUEST_URI} [P,QSA,L]
<Proxy balancer://upstream>
BalancerMember unix://home/aareez/diaspora/tmp/diaspora.sock|http://
</Proxy>
ProxyRequests Off
ProxyVia On
ProxyPreserveHost On
RequestHeader set X_FORWARDED_PROTO https
<Proxy *>
Require all granted
</Proxy>
<Directory /home/aareez/diaspora/public>
Options -MultiViews
Require all granted
</Directory>
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/softpedia.xyz/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/softpedia.xyz/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/softpedia.xyz/chain.pem
# Based on https://wiki.mozilla.org/Security/Server_Side_TLS - consider as global configuration
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128:AES256:AES:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK
SSLHonorCipherOrder on
SSLCompression off
</VirtualHost>
# sudo a2enmod rewrite
# a2enmod proxy_http
# sudo a2enmod headers
# sudo a2enmod ssl
# sudo a2enmod lbmethod_byrequests
# sudo a2enmod slotmem_shm
# sudo systemctl restart apache2

Start Diaspora Server

To start Diaspora, follow the steps below.

# cd /home/aareez/diaspora
# sudo ./script/server

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com