UbuntuUbuntu Based

How To Install Flarum on Ubuntu 24.04 LTS

Flarum is a remarkably fast and elegant forum platform designed for modern web communities. Built with PHP and JavaScript, this next-generation discussion software offers a clean, responsive interface that works flawlessly across all devices. Unlike traditional forum solutions, Flarum focuses on simplicity without sacrificing functionality, making it an excellent choice for community forums, customer support platforms, and discussion boards. This comprehensive guide walks you through the complete installation process on Ubuntu 24.04 LTS, from initial server preparation to final configuration. By following these steps carefully, you’ll have a fully functional forum running in approximately 30 to 45 minutes.

Prerequisites and System Requirements

Before beginning the Flarum installation process, ensure your server meets all necessary requirements for optimal performance and stability.

Server Requirements

You’ll need an Ubuntu 24.04 LTS server with at least 1GB of RAM, though 2GB is recommended for better performance. Allocate a minimum of 10GB disk space for the installation and future content growth. Root access or sudo privileges are essential for installing packages and configuring services. A stable internet connection ensures smooth package downloads and updates throughout the installation process.

Software Requirements

Flarum requires PHP 8.1 or higher, and fortunately, Ubuntu 24.04 ships with PHP 8.3 by default. You’ll need either MySQL 5.6+ or MariaDB 10.0.5+ as your database server—this guide uses MariaDB 10.11 for its performance advantages. Choose between Apache 2.4 or Nginx as your web server; we’ll focus on Apache for its widespread compatibility and ease of configuration. Composer 2.x, the PHP dependency manager, is crucial for installing and managing Flarum. Essential system packages include curl, unzip, and git.

Optional but Recommended Components

A registered domain name or subdomain pointing to your server’s IP address provides professional access to your forum. SSL certificates, particularly free ones from Let’s Encrypt, encrypt communications and boost search engine rankings. Basic command-line knowledge helps you navigate the installation process more confidently. SSH access to your remote server is necessary if you’re not working directly on a local machine.

Understanding these requirements ensures your forum runs smoothly and securely. Choosing appropriate server specifications prevents performance bottlenecks as your community grows.

Initial Server Preparation and Updates

Keeping your Ubuntu system updated is the foundation of server security and stability. Outdated packages can contain vulnerabilities that compromise your forum’s integrity.

Start by updating the package repository information:

sudo apt update

This command refreshes the list of available packages and their versions. Next, upgrade all installed packages to their latest versions:

sudo apt upgrade -y

The -y flag automatically confirms the upgrade process. Now install essential tools that you’ll need throughout the installation:

sudo apt install curl unzip git software-properties-common -y

These utilities serve specific purposes: curl downloads files from URLs, unzip extracts compressed archives, git enables version control operations, and software-properties-common manages repository configurations. This foundational step creates a stable environment for the Flarum installation ahead.

Install and Configure Apache Web Server

Apache serves as the bridge between visitors and your Flarum installation, handling HTTP requests and delivering forum content efficiently.

Installing Apache

Install the Apache web server with this straightforward command:

sudo apt install apache2 -y

Enable Apache to start automatically when your server boots:

sudo systemctl enable apache2

Verify that Apache is running correctly:

sudo systemctl status apache2

You should see an “active (running)” status in green, confirming successful installation and operation.

Configuring the Firewall

If you’re using UFW (Uncomplicated Firewall), allow HTTP and HTTPS traffic:

sudo ufw allow 'Apache Full'

This command opens both port 80 (HTTP) and port 443 (HTTPS). Check your firewall status:

sudo ufw status

Enabling Required Apache Modules

Flarum requires specific Apache modules for URL rewriting and security headers. Enable the rewrite module:

sudo a2enmod rewrite

Enable SSL support for encrypted connections:

sudo a2enmod ssl

Enable the headers module for security enhancements:

sudo a2enmod headers

Restart Apache to apply these changes:

sudo systemctl restart apache2

The rewrite module handles clean URLs, removing “index.php” from forum addresses. SSL support enables HTTPS encryption, protecting user data during transmission. The headers module adds security headers that prevent common web attacks.

Install PHP 8.3 and Required Extensions

PHP powers Flarum’s backend functionality, handling database operations, user authentication, and content processing.

Installing PHP and Extensions

Ubuntu 24.04 includes PHP 8.3 in its default repositories. Install PHP along with all required extensions:

sudo apt install php php-fpm php-cli php-common php-mysql libapache2-mod-php php-gd php-curl php-json php-xmlrpc php-intl php-bcmath php-zip php-mbstring php-fileinfo php-xml php-soap php-tokenizer php-apcu -y

This comprehensive command installs PHP core and essential extensions. Each extension serves a specific purpose: php-mysql enables database connectivity, php-gd handles image processing, php-curl manages HTTP requests, php-mbstring processes multibyte strings for internationalization, and php-tokenizer parses PHP code.

Verify your PHP installation:

php -v

You should see PHP 8.3 with version details displayed.

Configuring PHP Settings

Optimize PHP settings for Flarum’s requirements. Open the PHP configuration file:

sudo nano /etc/php/8.3/apache2/php.ini

Locate and modify these settings:

upload_max_filesize = 50M
post_max_size = 50M
memory_limit = 256M
max_execution_time = 360
date.timezone = Asia/Jakarta

Adjust the timezone to match your location. These values allow larger file uploads, allocate sufficient memory for Composer operations, and extend script execution time for intensive tasks. Save the file by pressing CTRL + X, then Y, then Enter.

Restart Apache to apply the changes:

sudo systemctl restart apache2

Proper PHP configuration prevents timeout errors during installation and ensures smooth forum operation under load.

Install Composer Dependency Manager

Composer manages Flarum’s PHP dependencies, downloading and updating required libraries automatically.

Download the Composer installer script:

curl -sS https://getcomposer.org/installer -o composer-setup.php

Install Composer globally, making it accessible from any directory:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Remove the setup file:

php -r "unlink('composer-setup.php');"

Verify successful installation:

composer --version

You should see the Composer version number, typically 2.7 or higher. Global installation means you can run Composer commands from any location without specifying full paths. This official installation method ensures you receive an authentic, unmodified version of Composer.

Install and Configure MariaDB Database Server

MariaDB stores all forum data, including user accounts, posts, settings, and extension configurations.

Installing MariaDB

Install the MariaDB server package:

sudo apt install mariadb-server -y

Start the MariaDB service:

sudo systemctl start mariadb

Enable MariaDB to start automatically on boot:

sudo systemctl enable mariadb

Check the service status:

sudo systemctl status mariadb

Securing MariaDB Installation

Run the security script to harden your database server:

sudo mysql_secure_installation

Follow the prompts carefully. First, press Enter for the current root password (none exists yet). When asked to switch to unix_socket authentication, choose N. Set a strong root password when prompted. Remove anonymous users by selecting Y. Disallow root login remotely for security by choosing Y. Remove the test database by selecting Y. Reload privilege tables to apply changes by choosing Y.

These security measures prevent unauthorized database access and eliminate default testing configurations that pose security risks.

Creating Flarum Database and User

Log into MariaDB as root:

sudo mysql -u root -p

Enter your root password when prompted. Create a dedicated database for Flarum:

CREATE DATABASE flarum;

Create a database user with a strong password:

CREATE USER 'flarum'@'localhost' IDENTIFIED BY 'your_secure_password_here';

Replace your_secure_password_here with a complex password containing letters, numbers, and special characters. Grant all privileges on the Flarum database to this user:

GRANT ALL PRIVILEGES ON flarum.* TO 'flarum'@'localhost';

Flush privileges to ensure changes take effect:

FLUSH PRIVILEGES;

Verify the database was created:

SHOW DATABASES;

You should see flarum listed among the databases. Exit MariaDB:

EXIT;

Using a dedicated database user rather than root follows the principle of least privilege, enhancing security by limiting potential damage from compromised credentials.

Download and Install Flarum

Now comes the exciting part—actually installing Flarum using Composer.

Creating Flarum Directory

Create the necessary directories for Flarum and Composer cache:

sudo mkdir -p /var/www/{.cache,.config,flarum}

This command creates multiple directories in one operation. The hidden directories (.cache and .config) store Composer’s temporary files.

Setting Proper Permissions

Change ownership of these directories to the Apache user:

sudo chown -R www-data:www-data /var/www/{.cache,.config,flarum}

The www-data user runs Apache processes. Files must be owned by this user so Apache can read and write them. Set appropriate permissions:

sudo chmod -R 775 /var/www/flarum

These permissions allow the owner and group to read, write, and execute, while others can read and execute but not modify files.

Installing Flarum Using Composer

Navigate to the Flarum directory:

cd /var/www/flarum

Set the required environment variables:

export COMPOSER_HOME="/var/www/.config"
export COMPOSER_CACHE_DIR="/var/www/.cache"

Install Flarum through Composer:

sudo -u www-data composer create-project flarum/flarum . --stability=beta

The dot (.) at the end installs Flarum in the current directory rather than creating a subdirectory. The --stability=beta flag ensures you get the latest stable release. This process downloads Flarum core and all dependencies, typically taking 3 to 5 minutes depending on your connection speed.

You’ll see Composer resolving dependencies, downloading packages, and generating autoload files. Wait patiently until the process completes.

Verifying Installation

List the installed files:

ls -lah

You should see directories like public, storage, vendor, and files including composer.json and composer.lock. The public directory contains web-accessible files, storage holds logs and cache, and vendor contains PHP dependencies.

Ensure critical directories have proper permissions:

sudo chmod -R 775 /var/www/flarum/storage /var/www/flarum/public/assets
sudo chown -R www-data:www-data /var/www/flarum

Permission issues cause the most common installation problems. These commands prevent such issues proactively.

Configure Apache Virtual Host for Flarum

Virtual hosts allow Apache to serve multiple websites from one server. Configure a dedicated virtual host for your Flarum installation.

Creating Virtual Host Configuration

Create a new configuration file:

sudo nano /etc/apache2/sites-available/flarum.conf

Paste this configuration, replacing yourdomain.com with your actual domain:

<VirtualHost *:80>
    ServerAdmin admin@yourdomain.com
    DocumentRoot /var/www/flarum/public
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com

    <Directory /var/www/flarum/public>
        Options FollowSymlinks
        AllowOverride All
        Require all granted
    </Directory>

    <Directory /var/www/flarum/public>
        RewriteEngine on
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php [QSA,L]
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/flarum_error.log
    CustomLog ${APACHE_LOG_DIR}/flarum_access.log combined
</VirtualHost>

Save and close the file. The DocumentRoot points to the public subdirectory, not the main Flarum directory—this prevents direct access to sensitive files. The rewrite rules create clean URLs by routing all requests through index.php.

Enabling Configuration and Site

Enable your new site configuration:

sudo a2ensite flarum.conf

Optionally disable the default Apache site:

sudo a2dissite 000-default.conf

Test your configuration for syntax errors:

sudo apachectl configtest

If you see “Syntax OK,” proceed. Otherwise, review your configuration file for typos. Reload Apache to apply changes:

sudo systemctl reload apache2

The separate error and access logs help troubleshoot issues specific to your Flarum installation.

Complete Flarum Installation via Web Interface

With server configuration complete, finish the installation through Flarum’s intuitive web interface.

Accessing Installation Wizard

Open your web browser and navigate to your domain (http://yourdomain.com) or server IP address. The Flarum installation wizard loads automatically, displaying a clean, modern interface.

Filling Installation Form

Complete the form with these details:

Forum Settings:

  • Forum Title: Enter your desired forum name

Database Configuration:

  • Host: localhost
  • Database Name: flarum
  • Username: flarum
  • Password: The password you created earlier for the database user
  • Table Prefix: Leave as default flarum_ or customize if needed

Administrator Account:

  • Admin Username: Choose a secure username (avoid “admin”)
  • Admin Email: Your email address for notifications
  • Admin Password: Create a strong, unique password
  • Confirm Password: Re-enter your password

Double-check all credentials for accuracy. Click the “Install Flarum” button.

Completing Installation

The installation process runs for 1 to 2 minutes, creating database tables and configuring your forum. Upon completion, you’ll see a success message and redirect to your forum’s homepage. Log in using your administrator credentials to access the admin dashboard.

The clean, minimalist interface showcases Flarum’s modern design philosophy. Your forum is now functional, though additional configuration optimizes performance and security.

Post-Installation Configuration and Security

Enhance your forum’s security and functionality with these essential post-installation steps.

Installing SSL Certificate

SSL encryption protects user data and improves search engine rankings. Install Certbot for Let’s Encrypt certificates:

sudo apt install certbot python3-certbot-apache -y

Obtain and install an SSL certificate:

sudo certbot --apache -d yourdomain.com -d www.yourdomain.com

Follow the prompts, providing your email address and agreeing to terms. Choose to redirect HTTP traffic to HTTPS when asked. Certbot automatically modifies your Apache configuration, adding HTTPS support.

Test automatic certificate renewal:

sudo certbot renew --dry-run

Let’s Encrypt certificates expire after 90 days, but Certbot automatically renews them. This dry run ensures the renewal process works correctly.

Configuring Flarum Basic Settings

Access your forum and click the admin icon (person with gear). Configure these essential settings:

Navigate to “Basics” and complete your forum description and welcome message. Under “Email,” configure SMTP settings for email notifications—many hosting providers offer SMTP services, or use external providers like SendGrid or Mailgun.

Set user registration preferences under “Permissions.” Decide whether registration requires email confirmation or admin approval. These settings control community growth and spam prevention.

Security Hardening

Ensure file permissions remain secure:

sudo chmod -R 755 /var/www/flarum
sudo chmod -R 775 /var/www/flarum/storage /var/www/flarum/public/assets

Keep only necessary firewall ports open:

sudo ufw status

Remove rules for unused services. Establish a regular update schedule, checking weekly for Flarum and extension updates.

Essential Flarum Extensions and Customization

Extensions expand Flarum’s functionality, adding features for moderation, SEO, and user engagement.

Understanding Flarum Extensions

Flarum’s extension system allows modular customization without core modifications. Official extensions come from the Flarum team, while community extensions offer additional features. Browse available extensions at discuss.flarum.org or packagist.org.

Installing Extensions via Composer

Navigate to your Flarum directory:

cd /var/www/flarum

Install an extension using Composer:

sudo -u www-data composer require flarum/tags

This example installs the official Tags extension. Clear Flarum’s cache:

php flarum cache:clear

Enable the extension from your admin panel under “Extensions.” Click the toggle switch to activate it.

Recommended Extensions

Consider these popular extensions for new forums:

Security extensions like flarum/suspend allow moderator actions against rule violators. SEO extensions improve search engine visibility through meta tags and sitemaps. User engagement extensions such as flarum/likes encourage interaction. Moderation tools like flarum/approval queue review content before publication.

Customizing Appearance

Access appearance settings from the admin panel. Modify primary and secondary colors to match your brand. Upload a custom logo and favicon for professional branding. Add custom header or footer HTML for analytics tracking or additional navigation. The appearance editor provides live preview as you make changes.

Maintenance and Updates

Regular maintenance keeps your forum secure, fast, and bug-free.

Updating Flarum

Always backup before updating. Export your database:

mysqldump -u flarum -p flarum > flarum-backup-$(date +%Y%m%d).sql

Update Flarum and all extensions:

cd /var/www/flarum
sudo -u www-data composer update --prefer-dist --no-dev -a --with-all-dependencies

Clear the cache after updating:

php flarum cache:clear

Check your forum for proper functionality after updates. Test critical features like posting, registration, and login.

Backup Strategy

Automate backups using cron jobs. Create a backup script that exports the database and archives forum files. Store backups off-site for disaster recovery. Maintain at least three recent backups, rotating older ones as space permits.

Monitoring and Logs

Check Apache logs for unusual activity:

sudo tail -f /var/log/apache2/flarum_error.log

Flarum stores application logs in the storage/logs directory. Review these logs when troubleshooting extension issues or errors.

Troubleshooting Common Issues

Even careful installations encounter occasional problems. These solutions address the most common issues.

500 Internal Server Error

Check Apache error logs first:

sudo tail -50 /var/log/apache2/flarum_error.log

Verify storage directory permissions:

sudo chmod -R 775 /var/www/flarum/storage
sudo chown -R www-data:www-data /var/www/flarum/storage

Increase PHP memory limit if errors mention memory exhaustion.

Blank Page After Installation

Enable PHP error display temporarily. Edit php.ini:

sudo nano /etc/php/8.3/apache2/php.ini

Set display_errors = On and restart Apache. Check for missing PHP extensions or syntax errors in configuration files. Clear your browser cache and cookies.

Database Connection Errors

Verify MariaDB is running:

sudo systemctl status mariadb

Check database credentials in the config.php file located at /var/www/flarum/config.php. Test database connection manually:

mysql -u flarum -p flarum

If connection fails, verify the user has proper privileges.

Composer Installation Failures

Composer may fail due to insufficient memory. Create a swap file to provide additional memory:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Alternatively, increase PHP’s memory limit temporarily:

php -d memory_limit=2G /usr/local/bin/composer create-project flarum/flarum . --stability=beta

Congratulations! You have successfully installed Flarum. Thanks for using this tutorial for installing Flarum community software on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Flarum website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button