Nov 14, 2024 3 min read

Diaspora: Self-Hosting Made Simple

Diaspora: Self-Hosting Made Simple
Table of Contents

Diaspora is an open-source, privacy-centric social media platform that empowers users to take control of their data by self-hosting their own "pod." It is a decentralized alternative to mainstream platforms, providing users with full ownership, customization, and the ability to connect to a global network of other Diaspora pods. In this guide, we’ll walk through deploying Diaspora, configuring it with Nginx, enabling logging, setting up backups, keeping it updated, and leveraging its unique features.

Installing Diaspora

πŸ“¦ Docker/Docker Compose Setup

Using Docker simplifies the deployment process by encapsulating all dependencies. Here’s how to create a docker-compose.yml file and start Diaspora:

  1. Create a new directory for Diaspora:

mkdir diaspora && cd diaspora

  1. Create a docker-compose.yml file with the following configuration:

version: '3.7'

services:

diaspora:

image: diaspora/diaspora:latest

container_name: diaspora

restart: always

ports:

- "3000:3000"

volumes:

- diaspora-data:/home/diaspora/diaspora/public/uploads

environment:

DB_HOST: db

DB_USER: diaspora

DB_PASS: diasporadbpassword

DB_NAME: diaspora_production

RAILS_ENV: production

db:

image: postgres:13

container_name: diaspora_db

restart: always

environment:

POSTGRES_USER: diaspora

POSTGRES_PASSWORD: diasporadbpassword

POSTGRES_DB: diaspora_production

volumes:

- diaspora-db:/var/lib/postgresql/data

volumes:

diaspora-data:

diaspora-db:

  1. Start the containers:

docker-compose up -d

  1. Verify the containers are running:

docker ps

πŸš€ Manual Installation

For a traditional setup on a Linux server, follow these steps:

  1. Install dependencies:

sudo apt update

sudo apt install -y git curl gnupg2 build-essential libssl-dev libreadline-dev libpq-dev zlib1g-dev libsqlite3-dev

  1. Clone the Diaspora repository:

git clone https://github.com/diaspora/diaspora.git

cd diaspora

  1. Install RVM (Ruby Version Manager) and Ruby:

curl -sSL https://get.rvm.io | bash -s stable

source ~/.rvm/scripts/rvm

rvm install 3.0.0

rvm use 3.0.0 --default

  1. Install Bundler and dependencies:

gem install bundler

bundle install --deployment --without test development

  1. Configure the database and application:

cp config/database.yml.example config/database.yml

cp config/diaspora.yml.example config/diaspora.yml

  1. Run the setup script:

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

  1. Start Diaspora:

RAILS_ENV=production bin/bundle exec thin start

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

To serve Diaspora, create an Nginx server block:

  1. Install Nginx:

sudo apt install nginx

  1. Create a new Nginx configuration file:

sudo nano /etc/nginx/sites-available/diaspora

  1. Add the following content:

server {

listen 80;

server_name example.com;

location / {

proxy_pass http://127.0.0.1:3000;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

  1. Enable the configuration:

sudo ln -s /etc/nginx/sites-available/diaspora /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

To secure the app with HTTPS:

  1. Install Certbot:

sudo apt install certbot python3-certbot-nginx

  1. Obtain and configure a certificate:

sudo certbot --nginx -d example.com

  1. Automate certificate renewal:

sudo crontab -e

Add the following line:


0 3 * * * certbot renew --quiet

Logging and Debugging Diaspora

πŸ—ƒοΈ Enabling Debug Logs

Enable detailed logs by editing the diaspora.yml file:


nano config/diaspora.yml

Set the log level to debug:


logging:

level: debug

Restart Diaspora to apply the changes.

πŸ“„ Viewing Logs

For Docker:


docker logs -f diaspora

For manual installations:


tail -f log/production.log

πŸ› οΈ Troubleshooting Common Issues

Check for database connection errors or misconfigurations in the logs. Example:


grep "ActiveRecord::" log/production.log

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup uploads and configuration files:


tar -czvf diaspora_backup.tar.gz config/ public/uploads/

πŸ”„ Database Backups

Export the database:


pg_dump -U diaspora diaspora_production > diaspora_db_backup.sql

Restore the database:


psql -U diaspora diaspora_production < diaspora_db_backup.sql

πŸ“… Automated Backup Scripts

Create a backup script /usr/local/bin/diaspora_backup.sh:


#!/bin/bash

tar -czvf /backup/diaspora_$(date +%F).tar.gz config/ public/uploads/

pg_dump -U diaspora diaspora_production > /backup/diaspora_db_$(date +%F).sql

Make it executable:


chmod +x /usr/local/bin/diaspora_backup.sh

Schedule it via cron:


crontab -e

Add:


0 2 * * * /usr/local/bin/diaspora_backup.sh

Updating and Upgrading Diaspora

⬆️ Updating Docker Images

Pull the latest image and redeploy:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installs, update the source code:


git pull origin stable

bundle install --deployment --without development test

RAILS_ENV=production bin/rake db:migrate

Restart the application:


RAILS_ENV=production bin/bundle exec thin restart

Leveraging Diaspora’s Unique Features

πŸ”§ Enabling APIs

Enable the API in diaspora.yml:


api:

enabled: true

Restart Diaspora, then test the API with curl:


curl -X GET http://example.com/api/v1/users

🌟 Advanced Configurations

To enable custom themes, place your files in public/custom/ and reference them in diaspora.yml.

Wrapping Up

Diaspora puts privacy and control back into your hands, making it an excellent choice for self-hosting your social media platform. By following this guide, you’ve set up Diaspora, secured it with Nginx, configured backups, and explored its features. Start connecting with a global community of other Diaspora pods while maintaining full ownership of your data!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.