Flarum is a lightweight, open-source forum software designed for simplicity, speed, and performance. Itโs highly customizable, making it an excellent choice for self-hosting, where you can maintain full control over your data and tailor the platform to your communityโs needs. In this guide, weโll cover installing Flarum, configuring Nginx, managing logs, setting up backups, updating Flarum, and utilizing its unique features.
Installing Flarum
๐ฆ Docker/Docker Compose Setup
To deploy Flarum using Docker, create and configure a docker-compose.yml
file that orchestrates Flarum along with its dependencies.
version: '3.7'
services:
app:
image: flarum/flarum:latest
container_name: flarum_app
ports:
- "8000:80"
volumes:
- flarum_data:/flarum/app
environment:
- FLARUM_DATABASE_HOST=db
- FLARUM_DATABASE_NAME=flarum
- FLARUM_DATABASE_USER=flarum_user
- FLARUM_DATABASE_PASSWORD=securepassword
db:
image: mariadb:10.8
container_name: flarum_db
volumes:
- db_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_DATABASE=flarum
- MYSQL_USER=flarum_user
- MYSQL_PASSWORD=securepassword
volumes:
flarum_data:
db_data:
Deploy Flarum using Docker Compose:
docker-compose up -d
This will spin up both the Flarum app and its database. Access your Flarum instance at http://<your_server_ip>:8000
.
๐ Manual Installation
To manually install Flarum on a Linux server, follow these steps:
- Install Dependencies: Ensure PHP, Composer, and a database (e.g., MySQL) are installed.
sudo apt update && sudo apt install -y php-cli php-mbstring php-xml unzip curl \
nginx mariadb-server composer
- Create a Database:
sudo mysql -u root -p
CREATE DATABASE flarum;
CREATE USER 'flarum_user'@'localhost' IDENTIFIED BY 'securepassword';
GRANT ALL PRIVILEGES ON flarum.* TO 'flarum_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
- Download and Install Flarum:
mkdir -p /var/www/flarum && cd /var/www/flarum
composer create-project flarum/flarum .
chown -R www-data:www-data /var/www/flarum
- Configure Permissions:
chmod -R 775 storage
chmod -R 775 public/assets
Flarum should now be accessible at your domain after configuring Nginx (covered next).
Configuring Nginx as a Reverse Proxy
๐ Nginx Configuration
Create an Nginx server block to route traffic to your Flarum application.
server {
listen 80;
server_name yourdomain.com;
root /var/www/flarum/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|otf)$ {
expires max;
log_not_found off;
}
}
Test and reload the configuration:
sudo nginx -t
sudo systemctl reload nginx
๐ SSL/TLS Setup
Secure Flarum with Let's Encrypt:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
Automate certificate renewals:
sudo systemctl enable certbot.timer
Logging and Debugging Flarum
๐๏ธ Enabling Debug Logs
Enable debug mode in Flarum by editing the config.php
file:
return [
'debug' => true,
// Other configurations...
];
๐ Viewing Logs
To view logs, access the following locations:
-
Docker:
docker logs flarum_app
-
Manual Installation:
/var/www/flarum/storage/logs/flarum.log
๐ ๏ธ Troubleshooting Common Issues
If you encounter errors, check:
-
Permissions for the
storage
andpublic/assets
directories. -
Database connection settings in
config.php
.
๐ค Exporting Logs
Set up log shipping to an external system (e.g., ELK Stack) with Filebeat:
sudo apt install -y filebeat
sudo filebeat modules enable nginx
sudo filebeat setup
sudo systemctl start filebeat
Backup and Restore
๐๏ธ File-Based Backups
Backup Flarumโs files:
tar -czvf flarum_backup_$(date +%F).tar.gz /var/www/flarum
๐ Database Backups
Export the database:
mysqldump -u flarum_user -p flarum > flarum_db_backup_$(date +%F).sql
Restore the database:
mysql -u flarum_user -p flarum < flarum_db_backup.sql
๐ Automated Backup Scripts
Automate backups with a cron job:
echo "0 2 * * * tar -czvf /backups/flarum_$(date +\%F).tar.gz /var/www/flarum && \
mysqldump -u flarum_user -p'password' flarum > /backups/flarum_db_$(date +\%F).sql" | crontab -
Updating and Upgrading Flarum
โฌ๏ธ Updating Docker Images
Update Flarum if using Docker:
docker-compose pull app
docker-compose up -d
๐ ๏ธ Manual Updates
For manual installations, update via Composer:
composer update
php flarum migrate
php flarum cache:clear
๐ Checking for Updates
Check for available updates on the Flarum GitHub repository.
Leveraging Flarumโs Unique Features
๐ง Enabling APIs
Activate Flarumโs API by setting appropriate permissions for extensions:
php flarum permission:grant api access
Use the API with tools like curl
:
curl -X GET "http://yourdomain.com/api/discussions" \
-H "Authorization: Token your_api_token"
๐ Advanced Configurations
Extend Flarum with extensions:
composer require flarum/extension-slug
php flarum cache:clear
Wrapping Up
In this guide, weโve covered everything from installation to advanced configurations for Flarum, a powerful self-hosted forum platform. By following these steps, you can enjoy full control over your forum while leveraging Flarumโs unique flexibility and performance. Start building your community today!