Install and Configure Diaspora on CentOS 7
Diaspora is an open-source social platform with a focus on user privacy. This tutorial explains how to install and configure a Diaspora pod on CentOS 7.
Prerequisites
- A CentOS 7 server setup
- At least 512MB RAM, 1GB swap space, and a multi-core CPU for standard pod operation
- An active sudo user
Install Required Packages
Start by retrieving and installing the latest EPEL release:
sudo yum install epel-release
Install the essential packages:
sudo yum install tar make automake gcc gcc-c++ git net-tools cmake libcurl-devel libxml2-devel libffi-devel libxslt-devel wget redis ImageMagick nodejs postgresql-devel
Activate Redis at system startup:
sudo systemctl enable redis
sudo systemctl start redis
Install and Configure PostgreSQL
While Diaspora also works with MySQL or MariaDB, this guide uses PostgreSQL.
Install PostgreSQL server and tools:
sudo yum install postgresql-server postgresql-contrib postgresql-setup initdb
Enable PostgreSQL to run at startup:
sudo systemctl enable postgresql
sudo systemctl start postgresql
Access the PostgreSQL prompt:
sudo -u postgres psql
Create a new PostgreSQL user for Diaspora:
CREATE USER diaspora WITH CREATEDB PASSWORD '<password>';
Add a Dedicated Diaspora User
Create a local system user for running Diaspora:
sudo adduser --disabled-login diaspora
Switch to this user session:
sudo su - diaspora
Install Ruby with rbenv
Install all required dependencies for Ruby:
sudo yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel
Clone and set up rbenv:
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
Reconnect as the Diaspora user to apply environment changes:
exit
sudo su - diaspora
Install ruby-build plugin for rbenv:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Install Ruby 2.4.3 and make it the global version:
rbenv install 2.4.3
rbenv global 2.4.3
Set Up Mail Server
Use Postfix as the mail transfer agent. Please refer to the appropriate guide to set up Postfix with Dovecot and Sieve for handling user mail.
Install and Configure Diaspora
Clone Diaspora’s master repository:
cd ~
git clone -b master https://github.com/diaspora/diaspora.git
cd diaspora
Copy sample config files:
cp config/database.yml.example config/database.yml
cp config/diaspora.yml.example config/diaspora.yml
Modify the database config file with your database credentials:
nano config/database.yml
Example PostgreSQL configuration block:
postgresql: &postgresql
adapter: postgresql
host: localhost
port: 5432
username: diaspora
password: __password__
encoding: unicode
Edit Diaspora config file with required values:
nano config/diaspora.yml
Make these changes:
- Set the
url
to your pod’s public address - Uncomment
certificate_authorities
- Set
rails_environment
to production - Set
require_ssl
to false
Install Gems with Bundler
Install bundler and configure the environment:
gem install bundler
script/configure_bundler
Note: If you receive version errors, edit .ruby-version
and specify 2.4.3
.
Set Up the Database
Create the database and run migrations:
RAILS_ENV=production bin/rake db:create db:migrate
Precompile Assets
Run this Rake command to generate the production-ready assets:
RAILS_ENV=production bin/rake assets:precompile
Set Up Diaspora with systemd
To manage Diaspora as a service, we’ll use systemd. Begin by creating the following files:
Create the target unit:
touch /etc/systemd/system/diaspora.target
Set up the web service unit:
touch /etc/systemd/system/diaspora-web.service
Create the sidekiq service file:
touch /etc/systemd/system/diaspora-sidekiq.service
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
diaspora-web.service
[Unit]
Description=Diaspora social network (unicorn)
PartOf=diaspora.target
StopWhenUnneeded=true
[Service]
User=diaspora
Environment=RAILS_ENV=production
WorkingDirectory=/home/diaspora/diaspora
ExecStart=/bin/bash -lc "bin/bundle exec unicorn -c config/unicorn.rb -E production"
Restart=always
[Install]
WantedBy=diaspora.target
diaspora-sidekiq.service
[Unit]
Description=Diaspora social network (sidekiq)
PartOf=diaspora.target
StopWhenUnneeded=true
[Service]
User=diaspora
Environment=RAILS_ENV=production
WorkingDirectory=/home/diaspora/diaspora
ExecStart=/bin/bash -lc "bin/bundle exec sidekiq"
Restart=always
[Install]
WantedBy=diaspora.target
Enable and Start Services
Activate all Diaspora-related services at boot:
sudo systemctl enable diaspora.target diaspora-sidekiq.service diaspora-web.service
sudo systemctl restart diaspora.target
Check service status:
sudo systemctl status diaspora-web.service
sudo systemctl status diaspora-sidekiq.service
Configure Nginx as a Reverse Proxy
Set up Nginx to proxy Diaspora and deliver static assets. Also use acme.sh to acquire a Let’s Encrypt SSL certificate.
Clone acme.sh
git clone https://github.com/Neilpang/acme.sh.git
Request a Certificate
./.acme.sh/acme.sh --issue --log \
--dns \
--keylength ec-256 \
--cert-file /etc/nginx/https/cert.pem \
--key-file /etc/nginx/https/key.pem \
--fullchain-file /etc/nginx/https/fullchain.pem \
-d example.com \
-d www.example.com
Install and Configure Nginx
sudo yum install nginx
nano /etc/nginx/conf.d/diaspora.conf
Paste this configuration:
upstream diaspora_server {
server unix:/home/diaspora/diaspora/tmp/diaspora.sock;
}
server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;
return 301 https://example.com$request_uri;
access_log /dev/null;
error_log /dev/null;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.example.com example.com;
if ($host = www.example.com) {
return 301 https://example.com$request_uri;
}
access_log /var/log/nginx/dspr-access.log;
error_log /var/log/nginx/dspr-error.log;
ssl_certificate /etc/nginx/https/fullchain.pem;
ssl_certificate_key /etc/nginx/https/key.pem;
ssl_protocols TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AESGCM:EECDH+AES;
ssl_ecdh_curve X25519:P-521:P-384:P-256;
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
resolver 80.67.169.40 80.67.169.12 valid=300s;
resolver_timeout 5s;
ssl_session_cache shared:SSL:10m;
root /home/diaspora/diaspora/public;
client_max_body_size 5M;
client_body_buffer_size 256K;
try_files $uri @diaspora;
location /assets/ {
expires max;
add_header Cache-Control public;
}
location @diaspora {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://diaspora_server;
}
}
Replace example.com
with your actual domain name.
Test and Reload Nginx
sudo nginx -t
sudo systemctl restart nginx
Allow Web Traffic Through Firewall
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Access Diaspora in Browser
Open your domain in a browser to see the Diaspora welcome screen: https://example.com
Create an Admin User
Create a Diaspora user by clicking “Start by creating an account.” After registering, assign admin rights:
Role.add_admin User.where(username: "your_username").first.person
Access the admin dashboard via:
https://example.com/admins/dashboard
Access Sidekiq Dashboard and Stats
- Sidekiq UI:
https://example.com/sidekiq
- Pod statistics:
https://example.com/statistics
Log Management with logrotate
Create a logrotate config file:
nano /etc/logrotate/diaspora
Insert the following configuration:
/home/diaspora/diaspora/log/*.log {
notifempty
copytruncate
missingok
compress
weekly
rotate 52
}
Update Diaspora
To upgrade Diaspora:
- Update all installed system packages:
sudo yum update
- Update the source code and gems:
su - diaspora
cd diaspora
git pull
gem install bundler
bin/bundle --full-index
Apply database changes and recompile:
RAILS_ENV=production bin/rake db:migrate
RAILS_ENV=production bin/rake assets:precompile
Restart Diaspora:
systemctl restart diaspora.target
Conclusion
By completing these steps, you’ve successfully deployed a private, production-grade Diaspora pod on CentOS 7. You’ve configured core components including PostgreSQL, Ruby, Nginx, and systemd services. With SSL encryption, log rotation, and proper user roles, your instance is secure, performant, and ready for use. Stay up-to-date by routinely updating the application and monitoring system health through Sidekiq and admin dashboards.