• Meta
  • Creating a modern open-source forum in 2024

https://i.imgur.com/Z3G44Bx.png

This is a small guide on what tools and extensions we used to create the FOSS Outpost forum. It could be helpful for any folks out there who want to create a modern forum suitable for 2024 standards, all using open-source software.

The Forum Script

There are a lot of open-source forum scripts out there. Perhaps the most famous one is Discourse, which is used in a lot of places, especially as an official forum script for Linux distributions.

There are also traditional and classic forum scripts like phpBB, MyBB, FluxBB and others.

Out of these, we opted for Flarum; an open-source PHP-based forum script, for the following reasons:

  • Discourse has a real issue in setting it up behind a Nginx reverse proxy, or at least, it is very hard/not straightforward to do it. We needed to set it up in a subfolder and as a virtual host on our server because we are hosting multiple websites on the same server and not just the forum itself.
  • Other forum scripts are very classic and outdated and don’t have a lot of the features we need.
  • Flarum is very simple; it is nothing more than a traditional PHP and MySQL script. This saves headaches in setting it up.
  • Flarum supports extensions, and there are a lot of them for everything you may need.
  • Flarum looks good enough on mobile devices by default, without further tweaks.

Setting Flarum up on the server took no time. The installation instructions are clear, and you can install it like any traditional PHP script as you have been doing since 2010.

Tweaking the Forum

Flarum is very minimalist by default. Apparently, its devs believe forums vary a lot from one another, so they have removed many core features and sent them to become “extensions” that you can install later on.

Flarum extensions can be easily installed by installing the “Extension Manager” extension. Yes; you first install the extension manager as a separate addon, and then use it to install others.

Extensions created by the Flarum community can be found at:

Best community software; modern, fast and free. For small to enterprise communities.

https://i.imgur.com/NTSnWHx.png

Here’s a list of the extensions we use at FOSS Outpost:

  • DL Pagination: Basic extension to add pagination support to the forum.
  • Discussion Views: Add a view counter to each post.
  • FancyBox: A nice extension for adding lightbox and media controls to post images.
  • FoF Formatting: Useful formatting options to the editor with additional autolink/auto-embed options.
  • FoF Links: Add custom links to the top bar.
  • FoF Polls: Ability to add polls to posts.
  • FoF Prevent Necrobumping: Useful extension to display a warning message if a user tries to post a reply to an old post.
  • FoF Share Social: Additional share options for posts and replies.
  • FoF Sitemap: Very important extension to generate sitemap files for posts, tags and comments. This is important so that you can push your sitemap files to Google and other search engines via platforms like Google Search Console. If you don’t do that, then your forum posts may not be indexed in search engines.
  • FoF Terms: Display a link for terms and conditions + privacy policy during registration.
  • FoF User Bio: Allow users to create bios about themselves in their profiles.
  • GDPR Data Management: One of the most important extensions for Flarum; it adds GDPR support, and allows users to export their content or delete their accounts whenever they want. Deleted users will still have their content (posts and replies) hosted at the forum, but it will be displayed under the “Anonymous” user instead of their old names.
  • Inject Header Tag: Useful extension to add tracking scripts and other HTML codes to the forum. We use Plausible for tracking visitors, which is another open-source tracking software that does not invade privacy.
  • Last Post Avatar: Display the avatar of the last user who replied to the post on the main page.
  • Link Preview: Display link previews in posts and replies instead of plain URLs.
  • SEO: Another important extension to make the forum suitable for search engines. It adds robots.txt file and social media cards, and allows adjusting the meta tags for the forum.
  • Stickiest: Adds the ability to stick a post on the main page. Flarum has this feature built-in, but they have a weird behaviour for it by default: Posts are only sticky once you see them for the first time. After that, they are regular posts and others can come atop them. This extension fixes the issue.
  • Syndication: Adds RSS feed support to the forum and also to every post and category/tag. This is useful if someone wants to follow a post or a specific category on the forum via RSS.
  • Color Circles: Add colored icons around the avatars of selected users. We do this to highlight our premium Patreon subscribers so that they stand among other forum contributors.

That’s all! It’s a big list of extensions, but installing and tweaking them shouldn’t take more than one or two hours of your time.

It is also fun to work with the extension manager to install extensions and discover what people have made for their forums.

Automating the Forum Scheduler

Flarum has a scheduler to run automated tasks. Automated tasks which some extensions may need to run regularly such as generating sitemaps and other things.

Normally, the user shouldn’t need to do this, but with Flarum, you need to manually run the scheduler with the following command:

cd /var/www/path_to_forum/public && php flarum schedule:run >> /dev/null 2>&1

We did this using a crontab -e automation that runs it every two hours:

0 */2 * * * cd /var/www/path_to_forum/public && php flarum schedule:run >> /dev/null 2>&1

Flarum Forum Backups

Sadly Flarum does not come with backup support by default, and there are no extensions to add remote backup support either. You have to manually backup the:

  • Forum files that are located in your web directory.
  • Database files via MySQL.

The best way to do both is via a simple Shell script that was provided by a Flarum user. The script first creates a copy of the database with the mysqldump command, and copy of the forum files, and then uses Rclone to upload all the files to a remote location like Google Drive and others.

You need to run the Rclone setup with your remote storage before you can use the script.

We modified the script a bit but here it is:

#!/usr/bin/env bash
NAMEDATE=`date +%F_%H-%M_%s`_`whoami` && echo $NAMEDATE
mkdir ~/flarum_backup/$NAMEDATE -m 0755 && echo "Directory Created"
mysqldump --no-tablespaces -u DATABASE_USER -p"DATABASE_PASSWORD" DATABASE_NAME | gzip > ~/flarum_backup/$NAMEDATE/db.sql.gz && echo "Database Dumped"
tar czf ~/flarum_backup/$NAMEDATE/files.tar.gz /var/www/path_to_forum/ && echo "Server Files Dumped"
chmod -R 0644 ~/flarum_backup/$NAMEDATE/* && echo "Directory Permission Restored"
/var/opt/path_to_rclone/rclone copy ~/flarum_backup/$NAMEDATE "gdrive:/$NAMEDATE"
rm -rf ~/flarum_backup/*
exit 0

After creating the backup, it will be pushed to remote storage via Rclone. After that, local backup files are removed.

You can run this backup script at each X number of hours with crontab -e:

0 */2 * * * ~/backup-outpost.sh

We host backups on Google Drive. Setting up Google Drive with Rclone is a little bit tricky, and requires that you switch your Google Drive Cloud API application from testing to published or otherwise you will lose your authentication token in two weeks.

Additionally, since you don’t want your Google Drive to get filled with backups, you need to create a Google Apps Script automation that removes backups that are older than X date. Here is the script we use for removing backups from Google Drive which are older than 24 backups (e.g. if there are 25 backups, then remove the oldest ones):

function removeOldFolders() {
  var folder = DriveApp.getFolderById('YOUR_FOLDER_ID'); // Replace 'YOUR_FOLDER_ID' with the ID of the folder you want to work with
  var folders = folder.getFolders();
  var folderArray = [];
  
  while (folders.hasNext()) {
    var currentFolder = folders.next();
    var folderName = currentFolder.getName();
    var folderCreated = currentFolder.getDateCreated();
    folderArray.push({name: folderName, created: folderCreated});
  }
  
  folderArray.sort(function(a, b) {
    return new Date(b.created) - new Date(a.created);
  });
  
  for (var i = 24; i < folderArray.length; i++) {
    var folderToRemove = folder.getFoldersByName(folderArray[i].name);
    while (folderToRemove.hasNext()) {
      var currentFolder = folderToRemove.next();
      currentFolder.setTrashed(true);
    }
  }
}

From the trigger options in Google Apps Script, you can run this script at whatever times you want:
https://i.imgur.com/KdFtlQA.png

We also discovered that since Google Drive does not empty its trash automatically unless it has been 30 days (with no setting to change that period), we needed another automation script to empty the trash so here it is:

function emptyTrashFolder() {
  var now = new Date();
  var trashFile = DriveApp.getTrashedFiles();
  
  while (trashFile.hasNext()) {
    var file = trashFile.next();
    Drive.Files.remove(file.getId());
  }
}

You can run this script daily if you like.


That’s all so far about Flarum and setting it up for a modern open-source forum in 2024. It needs some work to get it up and working, but once you set it up, it is all done and good.

Remember that Flarum is much more lightweight on your server than other forum scripts, as it is nothing more than a traditional PHP/MySQL script. With all of its modern features and elegant look & feel, it is worth it to go through some hassle to get it up and working.

Learn more about the software from its official website:

Best community software; modern, fast and free. For small to enterprise communities.

© 2024 FOSS Post. All rights reserved.