Skip to content

Deploying Friendica

Introduction

Friendica is an open-source, decentralized social networking platform that connects with other federated networks like Mastodon, Diaspora, and ActivityPub. Built with PHP and MySQL/MariaDB, Friendica enables you to host your own social network with full control over your data.

This guide covers deploying Friendica on Klutch.sh using a Dockerfile, configuring database connections, persistent storage, and best practices for production deployments.


Prerequisites

  • A Klutch.sh account (sign up here)
  • A GitHub repository for your Friendica deployment
  • Basic knowledge of Docker, PHP, and MySQL/MariaDB
  • A MySQL or MariaDB database (can be deployed separately on Klutch.sh)

1. Prepare Your Friendica Repository

    1. Create a new GitHub repository or fork an existing Friendica deployment repository
    2. Add a Dockerfile to the root of your repository (see sample below)
    3. Store large assets (uploads, database files, logs) outside Git; use persistent volumes

Refer to the Klutch.sh Quick Start Guide for repository setup and GitHub integration.


2. Sample Dockerfile

Here’s a production-ready Dockerfile using the official Friendica image:

FROM friendica:latest-apache
# Set working directory
WORKDIR /var/www/html
# Install additional extensions if needed
RUN apt-get update && apt-get install -y \
libmagickwand-dev \
&& docker-php-ext-install zip \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& rm -rf /var/lib/apt/lists/*
# Set proper permissions
RUN chown -R www-data:www-data /var/www/html
# Expose HTTP port
EXPOSE 80

For a custom build from source:

FROM php:8.2-apache
# Install dependencies
RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libgd-dev \
libzip-dev \
libmagickwand-dev \
libxml2-dev \
mariadb-client \
git \
&& docker-php-ext-install pdo pdo_mysql curl gd zip xml \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& rm -rf /var/lib/apt/lists/*
# Enable Apache modules
RUN a2enmod rewrite ssl headers
WORKDIR /var/www/html
# Clone Friendica stable version
RUN git clone https://github.com/friendica/friendica.git . \
&& git checkout stable
# Install Composer dependencies
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN composer install --no-dev --optimize-autoloader
# Set permissions
RUN chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html
EXPOSE 80
CMD ["apache2-foreground"]

3. Database Setup

Friendica requires a MySQL or MariaDB database:

Deploy Database on Klutch.sh

    1. Create a new app for your database using the official MySQL or MariaDB image
    2. Attach a persistent volume to /var/lib/mysql with at least 10GB storage
    3. Configure TCP traffic and set the internal port to 3306
    4. Note the database connection details for your Friendica app

For database deployment details, see the MySQL guide or MariaDB guide.


4. Environment Variables

Configure these environment variables in your Klutch.sh app settings:

Terminal window
# Database Configuration
MYSQL_HOST=your-db-host
MYSQL_PORT=3306
MYSQL_DATABASE=friendica
MYSQL_USER=friendica_user
MYSQL_PASSWORD=secure_password
# Friendica Configuration
FRIENDICA_URL=https://example-app.klutch.sh
FRIENDICA_ADMIN_MAIL=admin@yourdomain.com
FRIENDICA_TZ=America/New_York
FRIENDICA_LANG=en
# PHP Settings (Nixpacks environment variables)
PHP_MEMORY_LIMIT=512M
PHP_UPLOAD_MAX_FILESIZE=128M
PHP_POST_MAX_SIZE=128M
# Optional SMTP Configuration
FRIENDICA_SMTP_HOST=smtp.example.com
FRIENDICA_SMTP_PORT=587
FRIENDICA_SMTP_USERNAME=your-smtp-user
FRIENDICA_SMTP_PASSWORD=your-smtp-password

Note: Always store sensitive values like passwords as secrets in Klutch.sh. Never commit them to your repository.


5. Persistent Storage

Friendica requires persistent storage for uploads, photos, and configuration:

    1. In the Klutch.sh dashboard, navigate to your app’s storage settings
    2. Add a volume with mount path /var/www/html/photo and size 50GB for photos and uploads
    3. Add a volume with mount path /var/www/html/config and size 1GB for configuration
    4. (Optional) Add a volume with mount path /var/www/html/log and size 5GB for logs

Example volume configuration:

Mount Path: /var/www/html/photo
Size: 50GB
Mount Path: /var/www/html/config
Size: 1GB

This ensures your data persists across deployments.


6. Deploy to Klutch.sh

    1. Push your repository (including Dockerfile) to GitHub
    2. In the Klutch.sh dashboard, create a new app and connect your repository
    3. Klutch.sh will automatically detect the Dockerfile in the root directory
    4. Set the internal port to 80 and select HTTP traffic type
    5. Add the environment variables from section 4
    6. Attach persistent volumes as described in section 5
    7. Click “Deploy” to build and start your Friendica instance

Your Friendica instance will be available at a URL like https://example-app.klutch.sh.


7. Initial Setup

    1. Access your Friendica instance URL in a browser
    2. Follow the setup wizard to verify system requirements
    3. Database connection details should be pre-configured from environment variables
    4. Create your admin account with a strong password
    5. Configure site settings, timezone, and privacy options

8. Post-Deployment Configuration

Configure Federation

    1. Navigate to Admin → Site → Federation
    2. Enable ActivityPub protocol to connect with other federated networks
    3. Test federation by following accounts on other instances

Add Custom Domain (Optional)

    1. Follow the Klutch.sh custom domains guide
    2. Point your domain to your Klutch.sh app
    3. Update FRIENDICA_URL environment variable to your custom domain
    4. Redeploy your app

9. Production Best Practices

  • Keep Updated: Regularly update to the latest stable Friendica version
  • Backups: Implement automated backups of your database and volumes
  • Security: Use strong passwords and enable two-factor authentication for admin accounts
  • Monitoring: Track CPU, memory, and storage usage
  • SSL/TLS: Klutch.sh automatically provides HTTPS for all apps
  • Scaling: For larger instances, scale vertically or add Redis caching

Resources


Deploying Friendica on Klutch.sh provides you with a scalable, decentralized social networking platform. With proper database configuration, persistent storage, and regular maintenance, you’ll have a production-ready instance that can federate with the broader Fediverse.