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
- Create a new GitHub repository or fork an existing Friendica deployment repository
- Add a
Dockerfileto the root of your repository (see sample below) - 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 directoryWORKDIR /var/www/html
# Install additional extensions if neededRUN 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 permissionsRUN chown -R www-data:www-data /var/www/html
# Expose HTTP portEXPOSE 80For a custom build from source:
FROM php:8.2-apache
# Install dependenciesRUN 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 modulesRUN a2enmod rewrite ssl headers
WORKDIR /var/www/html
# Clone Friendica stable versionRUN git clone https://github.com/friendica/friendica.git . \ && git checkout stable
# Install Composer dependenciesCOPY --from=composer:latest /usr/bin/composer /usr/bin/composerRUN composer install --no-dev --optimize-autoloader
# Set permissionsRUN 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
- Create a new app for your database using the official MySQL or MariaDB image
- Attach a persistent volume to
/var/lib/mysqlwith at least 10GB storage - Configure TCP traffic and set the internal port to
3306 - 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:
# Database ConfigurationMYSQL_HOST=your-db-hostMYSQL_PORT=3306MYSQL_DATABASE=friendicaMYSQL_USER=friendica_userMYSQL_PASSWORD=secure_password
# Friendica ConfigurationFRIENDICA_URL=https://example-app.klutch.shFRIENDICA_ADMIN_MAIL=admin@yourdomain.comFRIENDICA_TZ=America/New_YorkFRIENDICA_LANG=en
# PHP Settings (Nixpacks environment variables)PHP_MEMORY_LIMIT=512MPHP_UPLOAD_MAX_FILESIZE=128MPHP_POST_MAX_SIZE=128M
# Optional SMTP ConfigurationFRIENDICA_SMTP_HOST=smtp.example.comFRIENDICA_SMTP_PORT=587FRIENDICA_SMTP_USERNAME=your-smtp-userFRIENDICA_SMTP_PASSWORD=your-smtp-passwordNote: 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:
- In the Klutch.sh dashboard, navigate to your app’s storage settings
- Add a volume with mount path
/var/www/html/photoand size 50GB for photos and uploads - Add a volume with mount path
/var/www/html/configand size 1GB for configuration - (Optional) Add a volume with mount path
/var/www/html/logand size 5GB for logs
Example volume configuration:
Mount Path: /var/www/html/photoSize: 50GB
Mount Path: /var/www/html/configSize: 1GBThis ensures your data persists across deployments.
6. Deploy to Klutch.sh
- Push your repository (including
Dockerfile) to GitHub - In the Klutch.sh dashboard, create a new app and connect your repository
- Klutch.sh will automatically detect the Dockerfile in the root directory
- Set the internal port to
80and select HTTP traffic type - Add the environment variables from section 4
- Attach persistent volumes as described in section 5
- 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
- Access your Friendica instance URL in a browser
- Follow the setup wizard to verify system requirements
- Database connection details should be pre-configured from environment variables
- Create your admin account with a strong password
- Configure site settings, timezone, and privacy options
8. Post-Deployment Configuration
Configure Federation
- Navigate to Admin → Site → Federation
- Enable ActivityPub protocol to connect with other federated networks
- Test federation by following accounts on other instances
Add Custom Domain (Optional)
- Follow the Klutch.sh custom domains guide
- Point your domain to your Klutch.sh app
- Update
FRIENDICA_URLenvironment variable to your custom domain - 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
- Friendica Official Website
- Friendica GitHub Repository
- Friendica Docker Hub
- Klutch.sh Quick Start Guide
- Klutch.sh Volumes Guide
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.