×
Community Blog How to Install and Configure Diaspora on Alibaba Cloud

How to Install and Configure Diaspora on Alibaba Cloud

In this tutorial, we will be installing and setting up a Diaspora pod on Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04 installed.

By Arslan Ud Din Shafiq, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Diaspora is an open source, distributed, user owned and non-profit social network based upon Diaspora software. Diaspora is a project of The Diaspora Foundation which was written in Ruby, under the AGPLv3 and MIT License.

In this tutorial, we will be installing and setting up a Diaspora pod using Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04 installed.

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

To install build-essential execute the command.

# sudo apt-get install build-essential

To install libssl-dev execute the command.

# sudo apt-get install libssl-dev

To install libcurl4-openssl-dev execute the command.

# sudo apt-get install libcurl4-openssl-dev

To install libxml2-dev execute the command.

# sudo apt-get install libxml2-dev

To install libxslt-dev execute the command.

# sudo apt-get install libxslt-dev

To install imagemagick execute the command.

# sudo apt-get install imagemagick

To install ghostscript execute the command.

# sudo apt-get install ghostscript

To install curl execute the command.

# sudo apt-get install curl

To install libmagickwand-dev execute the command.

# sudo apt-get install libmagickwand-dev

You will need to install Git on your server as well as local machine. To install and configure Git, follow the steps below.

# sudo apt-get install git

(Optional) Now execute the commands below to configure Git by providing your name and valid email address so that commit messages may contain your correct information.

# git config --global user.name "Aareez"
# git config --global user.email "xyz@example.com"

To install libpq-dev execute the command.

# sudo apt-get install libpq-dev

To install autoconf execute the command.

# sudo apt-get install autoconf

To install bison execute the command.

# sudo apt-get install bison

To install libyaml-dev execute the command.

# sudo apt-get install libyaml-dev

To install libreadline6-dev execute the command.

# sudo apt-get install libreadline6-dev

To install zlib1g-dev execute the command.

# sudo apt-get install zlib1g-dev

To install libncurses5-dev execute the command.

# sudo apt-get install libncurses5-dev

To install libffi-dev execute the command.

# sudo apt-get install libffi-dev

To install libgdbm3 execute the command.

# sudo apt-get install libgdbm3

To install libreadline-dev execute the command.

# sudo apt-get install libreadline-dev

To install libgdbm-dev execute the command.

# sudo apt-get install libgdbm-dev

To install redis-server execute the command.

# sudo apt-get install redis-server

To install patch execute the command.

# sudo apt-get install patch

To install ruby-dev execute the command.

# sudo apt-get install ruby-dev

To install liblzma-dev execute the command.

# 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

Type Y and hit Enter when you see the prompt. Nodejs should be installed successfully.

Install PostgreSQL Database

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

In the first step, install PostgreSQL repo.

# 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 -

Now install the PostgreSQL server by executing the command below.

# sudo apt-get -y install postgresql postgresql-contrib

Execute the following command to start and enable PostgreSQL server so that it can start automatically after reboot.

# sudo systemctl start postgresql
# sudo systemctl enable postgresql

Now connect to PostgreSQL server using postgres username.

# sudo -u postgres psql

Create a user and database for Diaspora.

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

To configure Exim4, execute the command below.

# 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

Now install ruby-build plugin to compile Ruby.

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

Now install rbenv using the command.

# sudo apt install rbenv

Now install Ruby by executing command below.

# rbenv install 2.4.3
# rbenv global 2.4.3

Install and Configure Diaspora

To install and configure Diaspora, follow the steps below.

Navigate to home directory

# cd ~

Clone source code for Diaspora.

# git clone -b master https://github.com/diaspora/diaspora.git

Navigate to /diaspora

# cd diaspora

Copy the example database configuration file to location required by Diaspora.

# cp config/database.yml.example config/database.yml
# cp config/diaspora.yml.example config/diaspora.yml

Now open the database configuration file in text editor and configure database.

# sudo nano config/database.yml

1

Now configure Diaspora file.

# sudo nano config/diaspora.yml

To make it work properly, make the following changes in opened file.

  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

Now install bundle by executing command below.

# 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

Now add the following text to target file.

# 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

Now add the following text to web service file.

# 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

Now add the following text to sidekiq service file.

# 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

Now enable to services so that on reboot, they can restart automatically.

# sudo systemctl enable diaspora.target diaspora-sidekiq.service diaspora-web.service

Restart the services by using command below.

# 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.

To install execute the command.

# sudo apt-get install apache2

Now you will need to start apache server by executing command below.

# sudo systemctl start apache2

To check status of apache server, execute the command below.

# sudo systemctl status apache2

To check installation, access IP address of your Alibaba Cloud ECS or your domain name that you have pointed to your IP address. In my case, I have accessed via domain name and the following screen loaded.

2

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

To install certbot, update the system using command.

# sudo apt-get update

Now install software-properties-common.

# sudo apt-get install software-properties-common

Add certbot repository.

# sudo add-apt-repository ppa:certbot/certbot

Again, update the system.

# sudo apt-get update

Now install python-certbot-apache

# sudo apt-get install python-certbot-apache

Now execute the following command for issuance of SSL certificate.

# sudo certbot certonly --standalone --register-unsafely-without-email -d softpedia.xyz

Generate dhparam.pem file.

# openssl dhparam -out /home/aareez/.acme.sh/softpedia.xyz_ecc/dhparam.pem 2048

Create nginx configuration file by executing the command below.

# sudo nano /etc/apache2/sites-available/diaspora.conf

Add the following text in opened file and save the file.

<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>

Now enable rewrite mode by executing command.

# sudo a2enmod rewrite

Now enable proxy mode by executing command.

# a2enmod proxy_http

Now enable headers by executing command.

# sudo a2enmod headers

Now enable SSL engine by using command.

# sudo a2enmod ssl

Now enable lbmethod_byrequests by using command.

# sudo a2enmod lbmethod_byrequests

Now enable slotmem_shm by using command.

# sudo a2enmod slotmem_shm

Now restart your apache to reload the updated settings.

# sudo systemctl restart apache2

Start Diaspora Server

To start Diaspora, follow the steps below.

Navigate to diaspora directory.

# cd /home/aareez/diaspora

Note: Remember to replace aareez with your username.

Start the server by executing command.

# sudo ./script/server

That's it! You can now access Diaspora via domain name or ECS IP address.

3

0 0 0
Share on

Alibaba Clouder

2,605 posts | 747 followers

You may also like

Comments