Creating a Friendica Server with Ubuntu 22.04 (2024 Edition)
Last Updated: February 2024 Original tutorial by nequalsonelifestyle.com, updated with current requirements and best practices
Table of Contents
- System Requirements
- Initial Server Setup
- Security Configuration
- Installing Dependencies
- Friendica Installation
- Web Server Configuration
- Final Configuration
- Monitoring and Logging
- Backup and Restore
- Troubleshooting Guide
- Maintenance and Updates
- Additional Notes
System Requirements
Minimum Requirements (as of 2024)
- Ubuntu 22.04 LTS
- PHP 8.x (PHP 8.1 or newer strongly recommended)
- MariaDB/MySQL with InnoDB and Barracuda support
- Apache2 web server
- 512MB RAM (1GB+ recommended)
- 1GB storage space (more needed for media storage)
Important Note: While Friendica technically supports PHP 7.4+, PHP 8.x is strongly recommended as PHP 7.4 reached end-of-life in November 2022. Using PHP 8.x provides better security, performance, and long-term support.
Current Version Information
- Latest Friendica: 2024.12 “Interrupted Fern”
- Notable Features:
- ActivityPub federation (OStatus removed)
- BlueSky integration support
- Prometheus monitoring support
- Enhanced security features
Initial Server Setup
Basic System Update
sudo apt update
sudo apt upgrade -y
Essential Security Packages
sudo apt install -y ufw fail2ban unattended-upgrades
Security Configuration
Firewall Setup
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Automatic Updates
sudo dpkg-reconfigure -plow unattended-upgrades
Installing Dependencies
PHP 8.x Installation
# Add repository for PHP 8.x
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
# Install PHP 8.2 and extensions
sudo apt install -y \
php8.2 \
php8.2-{mysql,curl,gd,xml,zip,mbstring,intl,cli,fpm,bcmath} \
mariadb-server \
git \
unzip \
curl
# Verify PHP version (must show 8.2.x)
php8.2 -v
Web Server and Database
sudo apt install -y apache2 mariadb-server
Additional Tools
sudo apt install -y git curl pwgen
Global Composer Installation
# Install prerequisites
sudo apt install -y php-cli unzip curl
# Download and verify installer
HASH=`curl -sS https://composer.github.io/installer.sig`
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('/tmp/composer-setup.php'); } echo PHP_EOL;"
# Install globally
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
# Clean up
rm /tmp/composer-setup.php
# Verify installation
composer --version
Composer Directory Setup
# Create required directories
sudo mkdir -p /var/www/.composer
sudo mkdir -p /var/www/.cache/composer
sudo mkdir -p /var/www/.config/composer
# Set ownership
sudo chown -R www-data:www-data /var/www/.composer
sudo chown -R www-data:www-data /var/www/.cache
sudo chown -R www-data:www-data /var/www/.config
# Configure Composer home for www-data
sudo -u www-data composer config --global home /var/www/.composer
Friendica Installation
Prepare Web Directory
# Set proper ownership
sudo chown -R www-data:www-data /var/www
cd /var/www
sudo mv html html.bak
# Become www-data user for subsequent commands
sudo -u www-data bash
cd /var/www
Clone Friendica
# As www-data user
git clone https://github.com/friendica/friendica.git -b stable html
cd html
Install Composer Dependencies
# First, verify PHP version meets requirements
php -v
# Check composer version
composer --version
# Update composer if needed
sudo composer self-update
# Set COMPOSER_HOME for www-data user
sudo -u www-data composer config --global home /var/www/.composer
# Install dependencies as www-data user
sudo -u www-data composer install --no-dev
Setup Directories
sudo -u www-data mkdir -p view/smarty3
sudo -u www-data chmod 775 view/smarty3
Install Addons
sudo -u www-data git clone https://github.com/friendica/friendica-addons.git -b stable addon
Configure .htaccess
# Make sure you're in the Friendica root directory
cd /var/www/html
# Copy the .htaccess template file
sudo -u www-data cp .htaccess-dist .htaccess
# Verify the file was created
ls -la .htaccess
Web Server Configuration
Apache Configuration
First, add global ServerName to suppress FQDN warning:
# Add global ServerName to apache2.conf
echo "ServerName socialsoft.us" | sudo tee -a /etc/apache2/apache2.conf
Create virtual host configuration in /etc/apache2/sites-available/friendica.conf
:
<VirtualHost *:80>
ServerAdmin info@socialsoft.us
ServerName socialsoft.us
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/friendica_error.log
CustomLog ${APACHE_LOG_DIR}/friendica_access.log combined
<Directory /var/www/html>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
# Additional security headers
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
Header set Referrer-Policy "same-origin"
</Directory>
</VirtualHost>
Enable required modules and site:
# Enable required modules
sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod proxy_fcgi
sudo a2enmod setenvif
sudo a2enmod ssl
# Verify Apache configuration
sudo apache2ctl -t
# Enable site and disable default
sudo a2dissite 000-default.conf
sudo a2ensite friendica.conf
sudo systemctl restart apache2
Important: After enabling modules, Apache MUST be restarted for changes to take effect.
Enable Required Modules
sudo a2enmod rewrite
sudo a2enmod headers
sudo systemctl restart apache2
Final Configuration
SSL Certificate (Let's Encrypt)
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache
Set Permissions
sudo chown -R www-data:www-data /var/www/html
Monitoring and Logging
Prometheus Metrics Setup
# Enable the prometheus addon
sudo -u www-data php8.2 bin/console addon enable prometheus
# Configure prometheus endpoint in .htconfig.php
$config['system']['prometheus_enabled'] = true;
$config['system']['prometheus_endpoint'] = '/metrics';
Log Rotation Setup
Create a new logrotate configuration:
sudo nano /etc/logrotate.d/friendica
Add the following configuration:
/var/log/friendica/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 www-data www-data
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
}
Performance Monitoring
Monitor key metrics using:
# Check PHP-FPM status
sudo systemctl status php8.2-fpm
# Monitor Apache performance
sudo apachectl status
# Check MariaDB performance
mysqltuner --user root --pass your_password
# Monitor system resources
htop
Backup and Restore
Database Backup
# Create backup directory
sudo mkdir -p /var/backups/friendica
sudo chown www-data:www-data /var/backups/friendica
# Backup database
sudo -u www-data mysqldump -u friendica -p friendicadb > /var/backups/friendica/db_backup_$(date +%Y%m%d).sql
# Compress backup
sudo -u www-data gzip /var/backups/friendica/db_backup_$(date +%Y%m%d).sql
File System Backup
# Backup Friendica files
sudo -u www-data tar -czf /var/backups/friendica/files_$(date +%Y%m%d).tar.gz /var/www/html
# Backup configuration
sudo -u www-data cp /var/www/html/.htconfig.php /var/backups/friendica/htconfig_$(date +%Y%m%d).php
Restore Procedures
# Restore database
gunzip /var/backups/friendica/db_backup_YYYYMMDD.sql.gz
mysql -u friendica -p friendicadb < /var/backups/friendica/db_backup_YYYYMMDD.sql
# Restore files
cd /var/www
sudo -u www-data tar -xzf /var/backups/friendica/files_YYYYMMDD.tar.gz
# Restore config
sudo -u www-data cp /var/backups/friendica/htconfig_YYYYMMDD.php /var/www/html/.htconfig.php
Troubleshooting Guide
Database Connection Issues
# Check MariaDB status
sudo systemctl status mariadb
# Verify database exists
mysql -u root -p -e "SHOW DATABASES;"
# Check database permissions
mysql -u root -p -e "SHOW GRANTS FOR 'friendica'@'localhost';"
Permission Issues
# Reset ownership of Friendica directory
sudo chown -R www-data:www-data /var/www/html
# Reset permissions
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
# Make storage directory writable
sudo chmod 750 /var/www/html/storage
PHP Version Conflicts
# Check current PHP version
php -v
# List installed PHP versions
update-alternatives --list php
# Switch PHP version if needed
sudo update-alternatives --set php /usr/bin/php8.2
Composer Dependency Problems
# Clear composer cache
sudo -u www-data composer clear-cache
# Update dependencies
sudo -u www-data composer update --no-dev
# Remove vendor directory and reinstall
sudo -u www-data rm -rf vendor/
sudo -u www-data composer install --no-dev
Common Error Solutions
White Screen of Death
- Check PHP error log:
sudo tail -f /var/log/apache2/error.log
- Increase PHP memory limit in php.ini
- Enable PHP error reporting temporarily
- Check PHP error log:
Database Errors
- Verify database credentials in config file
- Check MariaDB logs:
sudo tail -f /var/log/mysql/error.log
- Run database updates:
sudo -u www-data php8.2 bin/console dbstructure update
Federation Issues
- Check DNS settings
- Verify SSL certificate
- Test with federation tester
Maintenance and Updates
Update Friendica
cd /var/www/html
sudo -u www-data git pull
sudo -u www-data composer install --no-dev
sudo -u www-data bin/console maintenance:update
Monitor System
- Use the built-in Prometheus exporter for monitoring
- Regular backup of database and user data
- Keep system and PHP packages updated
Additional Notes
New Features (2024)
- BlueSky Integration Setup
- Prometheus Monitoring
- Enhanced Security Headers
- Improved Installation Wizard
Removed Features
- OStatus protocol support (removed in 2024.12)
- Legacy authentication methods
For more information, visit: – Official Friendica Documentation – Friendica GitHub Repository
Friendica 2024.12 Installation Guide
For Ubuntu 22.04 LTS with existing LAMP stack
Prerequisites
- Existing LAMP stack on Ubuntu 22.04 LTS
- PHP 8.2 or higher (strongly recommended)
- Existing MariaDB/MySQL database with user and permissions configured
- Apache2 with required modules
1. Verify PHP Version and Extensions
# Verify PHP version (should be 8.x)
php -v
# Install required PHP extensions if not already present
sudo apt install php8.2-{mysql,curl,gd,xml,zip,mbstring,intl,cli,fpm}
2. Install Composer
# Install Composer globally
sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
# Verify installation
composer --version
# Configure Composer for www-data user
sudo -u www-data composer config --global home /var/www/.composer
3. Directory Setup
# Create Friendica directory
sudo mkdir -p /var/www/friendica
sudo chown www-data:www-data /var/www/friendica
4. Install Friendica
# Clone Friendica repository
sudo -u www-data git clone https://git.friendi.ca/friendica/friendica.git /var/www/friendica
cd /var/www/friendica
# Install dependencies
sudo -u www-data composer install --no-dev
# Clone addons repository
sudo -u www-data git clone https://git.friendi.ca/friendica/friendica-addons.git /var/www/friendica/addon
# Copy and configure .htaccess
sudo -u www-data cp .htaccess-dist .htaccess
5. SSL Configuration
# Install certbot
sudo apt install certbot python3-certbot-apache
# Obtain SSL certificate (replace example.com with your domain)
sudo certbot --apache -d example.com
# Enable SSL module if not already enabled
sudo a2enmod ssl
6. Apache Virtual Host Configuration
# Create virtual host configuration
sudo nano /etc/apache2/sites-available/friendica.conf
Add the following configuration (adjust domain and paths as needed):
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/friendica
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
<Directory /var/www/friendica>
Options Indexes FollowSymLinks MultiViews
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.conf
sudo systemctl restart apache2
7. Worker/Daemon Setup
Choose one of these methods:
Option A: Cron (Recommended)
# Edit www-data's crontab
sudo -u www-data crontab -e
# Add this line:
*/10 * * * * cd /var/www/friendica && /usr/bin/php8.2 bin/worker.php
Option B: Daemon
# Create systemd service file
sudo tee /etc/systemd/system/friendica-daemon.service <<EOF
[Unit]
Description=Friendica daemon
After=network.target mysql.service apache2.service
Requires=mysql.service apache2.service
[Service]
Type=simple
User=www-data
ExecStart=/usr/bin/php8.2 /var/www/friendica/bin/daemon.php
WorkingDirectory=/var/www/friendica
Restart=always
RestartSec=10
StandardOutput=append:/var/log/friendica-daemon.log
StandardError=append:/var/log/friendica-daemon.error.log
[Install]
WantedBy=multi-user.target
EOF
# Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable friendica-daemon
sudo systemctl start friendica-daemon
# Check status
sudo systemctl status friendica-daemon
Important: Only use ONE method (either cron or daemon). Using both simultaneously can cause issues.
8. Monitoring and Logging
Log Rotation Setup
sudo nano /etc/logrotate.d/friendica
Add the following:
/var/log/apache2/friendica_*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 640 www-data adm
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
}
9. Maintenance and Updates
# Update Friendica core
cd /var/www/friendica
sudo -u www-data git pull
sudo -u www-data composer install --no-dev
# Update addons
cd addon
sudo -u www-data git pull
Troubleshooting
Common Issues
Permission Issues
- Verify directory ownership:
ls -l /var/www/friendica
- Fix permissions if needed:
sudo chown -R www-data:www-data /var/www/friendica
- Verify directory ownership:
PHP Version Conflicts
- Check PHP version:
php -v
- Ensure using PHP 8.x:
sudo update-alternatives --config php
- Check PHP version:
SSL Certificate Issues
- Renew certificate:
sudo certbot renew
- Check certificate status:
sudo certbot certificates
- Renew certificate:
Security Best Practices
- Keep PHP and Composer up to date
- Regularly update Friendica and its dependencies
- Enable and configure firewall (UFW)
- Regular system updates
- Monitor log files for suspicious activity
Backup Procedures
# File system backup
sudo tar -czf friendica_files_$(date +%Y%m%d).tar.gz /var/www/friendica
# Configuration backup
sudo tar -czf friendica_config_$(date +%Y%m%d).tar.gz /etc/apache2/sites-available/friendica.conf
For support, visit the Friendica Support Forum or GitHub Issues.