Nov 14, 2024 4 min read

Friendica: Your Self-Hosting Setup and Management Guide

Friendica: Your Self-Hosting Setup and Management Guide
Table of Contents

Friendica is a decentralized, federated social networking platform designed for self-hosting. It connects seamlessly with the Fediverse and supports interoperability with platforms like Mastodon, Diaspora, and more. Friendica empowers users by offering full control over their data, extensive customization options, and the ability to integrate with other social networks. In this guide, we’ll walk through deploying, configuring, and managing Friendica, covering installation, reverse proxy setup, logging, backups, updates, and advanced features.

Installing Friendica

πŸ“¦ Docker/Docker Compose Setup

Using Docker Compose is one of the easiest ways to deploy Friendica. Below is a docker-compose.yml file tailored for Friendica, complete with a MariaDB backend.


version: '3.7'

services:

db:

image: mariadb:10.5

container_name: friendica-db

restart: always

environment:

MYSQL_ROOT_PASSWORD: secret_root_password

MYSQL_DATABASE: friendica

MYSQL_USER: friendica_user

MYSQL_PASSWORD: secret_password

volumes:

- friendica_db_data:/var/lib/mysql

app:

image: friendica/friendica:stable

container_name: friendica-app

restart: always

environment:

DBTYPE: mysql

MYSQL_HOST: db

MYSQL_DATABASE: friendica

MYSQL_USER: friendica_user

MYSQL_PASSWORD: secret_password

ADMIN_MAIL: [email protected]

ADMIN_PASSWORD: admin_password

ports:

- "8080:80"

volumes:

- friendica_data:/var/www/html

depends_on:

- db

volumes:

friendica_data:

friendica_db_data:

Deploy Friendica using the following commands:


docker-compose up -d

This will start the Friendica app and its database on your server. Access it via your server's IP address or domain on port 8080.

πŸš€ Manual Installation

For those who prefer direct control, here are the steps to manually install Friendica on a Linux server.

  1. Install required dependencies:

sudo apt update && sudo apt upgrade -y

sudo apt install -y apache2 mariadb-server php php-mysql php-gd php-xml php-mbstring git unzip

  1. Set up the database:

sudo mysql -u root -p

CREATE DATABASE friendica;

CREATE USER 'friendica_user'@'localhost' IDENTIFIED BY 'secret_password';

GRANT ALL PRIVILEGES ON friendica.* TO 'friendica_user'@'localhost';

FLUSH PRIVILEGES;

EXIT;

  1. Clone the Friendica repository and configure it:

cd /var/www

sudo git clone https://github.com/friendica/friendica.git friendica

sudo git clone https://github.com/friendica/friendica-addons.git friendica/addon

sudo chown -R www-data:www-data /var/www/friendica

sudo chmod -R 755 /var/www/friendica

  1. Configure Apache:

sudo nano /etc/apache2/sites-available/friendica.conf

Add the following:


<VirtualHost *:80>

ServerName yourdomain.com

DocumentRoot /var/www/friendica

<Directory /var/www/friendica>

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/friendica_error.log

CustomLog ${APACHE_LOG_DIR}/friendica_access.log combined

</VirtualHost>

Enable the site and restart Apache:


sudo a2ensite friendica

sudo a2enmod rewrite

sudo systemctl restart apache2

Access your Friendica instance via the domain or IP you configured.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

Set up Nginx as a reverse proxy to route traffic to Friendica:


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

Add the following configuration:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://localhost:8080;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

Enable the configuration and reload Nginx:


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

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Secure your Friendica instance with Let's Encrypt:


sudo apt install certbot python3-certbot-nginx -y

sudo certbot --nginx -d yourdomain.com

Set up automatic certificate renewal:


sudo crontab -e

Add the following:


0 0 * * * certbot renew --quiet

πŸ› οΈ Testing and Reloading Nginx

Validate the Nginx configuration and reload the service:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging Friendica

πŸ—ƒοΈ Enabling Debug Logs

To enable debug logging in Friendica, edit the config/local.config.php file:


<?php

return [

'system' => [

'loglevel' => 4, // 4 is debug level

],

];

πŸ“„ Viewing Logs

If using Docker, check logs with:


docker logs friendica-app

For manual installations, view logs in Apache or Friendica’s log directory:


tail -f /var/log/apache2/friendica_error.log

πŸ› οΈ Troubleshooting Common Issues

Check for database connection errors or misconfigured domains in the logs. Adjust environment variables or configuration files as needed.

πŸ“€ Exporting Logs

Forward logs to an ELK stack using filebeat:


sudo apt install filebeat

sudo nano /etc/filebeat/filebeat.yml

Configure Friendica logs as an input, then restart filebeat.

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup Friendica’s files:


tar -czvf friendica_backup_$(date +%F).tar.gz /var/www/friendica

πŸ”„ Database Backups

Dump the database:


mysqldump -u friendica_user -p friendica > friendica_db_backup.sql

πŸ“… Automated Backup Scripts

Add a cron job for automated backups:


crontab -e

Add:


0 2 * * * tar -czvf /path/to/backups/friendica_$(date +\%F).tar.gz /var/www/friendica

0 3 * * * mysqldump -u friendica_user -pYOURPASSWORD friendica > /path/to/backups/friendica_db_$(date +\%F).sql

Updating and Upgrading Friendica

⬆️ Updating Docker Images

Update the Friendica Docker image:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations:


cd /var/www/friendica

sudo git pull origin stable

sudo chown -R www-data:www-data /var/www/friendica

πŸ” Checking for Updates

Visit the Friendica admin panel to check for available updates.

Leveraging Friendica’s Unique Features

πŸ”§ Enabling APIs

Enable the Friendica API by adjusting the configuration:


<?php

return [

'system' => [

'api_enabled' => true,

],

];

You can now make API requests, such as fetching user posts:


curl -X GET -H "Authorization: Bearer <your-token>" https://yourdomain.com/api/statuses/user_timeline

🌟 Advanced Configurations

Enable advanced federation settings by modifying config/local.config.php:


<?php

return [

'system' => [

'diaspora' => true,

'gnusocial' => true,

],

];

Wrapping Up

This guide covered the essential steps to deploy, configure, and manage Friendica, including installation, reverse proxy setup, logging, backups, updates, and advanced features. By self-hosting Friendica, you gain unmatched control over your social networking experience while maintaining privacy and customization. Start implementing the provided examples today to unlock the full potential of Friendica!

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.