Flarum is free and open-source forum software in PHP, JavaScript, and TypeScript. It is next-generation forum software designed to be minimal with high extensibility through extensions. Flarum is a modern solution for Forum software, it’s fast, simple, and easy to use and install.

In this tutorial, we’ll show you how to install Flarum on Ubuntu 24.04. You will install Flarum with the LAMP Stack (Linux, Apache, MySQL/MariaDB, and PHP), then secure it via HTTPS using Certbot and letsencrypt.

Prerequisites

To follow with this tutorial, ensure you have the following requirements:

  • An Ubuntu 24.04 ‘Noble Numbat’.
  • A non-root user with administrator privileges.
  • An UFW (Uncomplicated Firewall) running.
  • A domain name pointed to a server IP address.

Installing Dependencies

Flarum is an open-source forum software written in PHP. To install it, you need to install dependencies to your Ubuntu server. This includes the LAMP Stack (Linux, Apache, MySQL/MariaDB), Git, and Composer.

In this section, you will install dependencies for Flarum via the Ubuntu repository.

First, run the command below to update your Ubuntu package index.

sudo apt update

<img alt="update repo" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/4-update-repo.png6635160d13088.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="189" loading="lazy" src="data:image/svg xml,” width=”669″>

Now run the following commands to install dependencies such as LAMP Stack (Linux, Apache, MySQL/MariaDB, and PHP), Composer, and Git to your Ubuntu system.

sudo apt install apache2 mariadb-server php php-common php-mysql libapache2-mod-php php-gd php-curl php-json php-xmlrpc php-intl php-bcmath php-zip php-apcu php-mbstring php-fileinfo php-xml php-soap php-tokenizer composer git

Type Y to confirm the installation.

<img alt="install dependencies" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/5-install-deps.png6635160d50ad3.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="227" loading="lazy" src="data:image/svg xml,” width=”750″>

After the installation, check the Apache service status with the following command. You will see the Apache web server is enabled with the status ‘active (running)‘.

sudo systemctl is-enabled apache2

sudo systemctl status apache2

<img alt="check apache2" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/6-check-apache2.png6635160d6f0d2.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="211" loading="lazy" src="data:image/svg xml,” width=”750″>

Now verify the MariaDB server with the following command. You will see a similar output, where the MariaDB is enabled and running.

sudo systemctl is-enabled mariadb

sudo systemctl status mariadb

<img alt="check mariadb" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/7-check-mariadb.png6635160d905e3.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="226" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, check the PHP and Composer versions with the following command. You will see that PHP 8.3 and Composer 2.7.1 is installed on your Ubuntu system.

php -v

sudo -u www-data composer -v

<img alt="check php composer" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/8-check-php-composer.png6635160dba8fc.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="329" loading="lazy" src="data:image/svg xml,” width=”693″>

Setting up UFW (Uncomplicated Firewall)

After installing dependencies, you need to allow access to the Apache web server via UFW (Uncomplicated Firewall). The Apache web server provides a UFW application profile ‘Apache Full‘ to allow both HTTP and HTTPS access.

Run the command below to open both HTTP and HTTPS access via the ‘Apache Full‘ profile. When added, you will see an output ‘Rules Added‘.

sudo ufw allow 'Apache Full'

Now verify the list rules on your UFW with the following command.

sudo ufw status

You should get the ‘Apache Full‘ profile enabled on your firewall. With this, both HTTP and HTTPS access to your Apache web server is allowed.

<img alt="setup ufw" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/9-setup-ufw.png6635160de9b18.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="293" loading="lazy" src="data:image/svg xml,” width=”568″>

Configuring PHP

In this section, you will configure PHP for Flarum by editing the ‘php.ini’ file. You will need to adjust some PHP configurations such as memory_limit and upload_max_filesize for your Flarum installation.

Open the default PHP configuration ‘php.ini‘ using the following nano editor command.

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

Change the default PHP configuration with the following. Make sure to adjust the value for the memory_limit and date.timezone options.

memory_limit = 512M

upload_max_filesize = 150M

max_execution_time = 600

date.timezone = Europe/Paris

When finished, save the file and exit.

Now run the command below to restart the Apache web server and apply the new PHP configuration.

sudo systemctl restart apache2

Configuring MariaDB server

After configuring PHP, you will secure the MariaDB server and create a new database and user that will be used by Flarum. You can secure MariaDB via the ‘mariadb-secure-installation‘ command, then create a new database and user via the ‘mariadb‘ client.

To secure the MariaDB server, execute the ‘mariadb-secure-installation‘ command below. With this, you will be asked about some of MariaDB’s configurations.

sudo mariadb-secure-installation

Below is the configuration you will be asked for:

  • The default MariaDB installation comes without a password, press ENTER when prompted for the password.
  • Now input Y to set up the MariaDB root password. Then, type the new password for MariaDB and repeat the password.
  • Input Y to remove the anonymous user from your MariaDB installation.
  • Input Y again when prompted to disable the remote login for the MariaDB root user.
  • Input Y to remove the default database test from your MariaDB.
  • Lastly, input Y to reload table privileges and apply new changes.

Once MariaDB is secured, log in to the MariaDB server with the following command. Type your MariaDB root password when prompted.

sudo mariadb -u root -p

Now run the following queries to create a new database and user for Flarum. In this example, you will create a new database ‘flarum‘, a user ‘flarum‘, with the password ‘password‘. You can replace those with your information.

CREATE DATABASE flarum;

CREATE USER flarum@localhost IDENTIFIED BY 'password';

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

FLUSH PRIVILEGES;

<img alt="create database" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/10-create-database.png6635160e14a17.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="255" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, run the query below to verify the privileges of user ‘flarum‘. This will ensure that user ‘flarum‘ can access the database ‘flarum‘.

SHOW GRANTS FOR flarum@localhost;

You can see below the user ‘flarum‘ can access the database ‘flarum‘.

Now type quit to exit from the MariaDB server.

<img alt="show privileges" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/11-show-privileges.png6635160e31acc.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="265" loading="lazy" src="data:image/svg xml,” width=”730″>

Downloading Flarum source code

With all dependencies configured, you’re ready to download Flarum source code. In this section, you will create a new document root directory for Flarum, then download the Flarum source code via Composer.

First, run the command below to create a new Flarum installation directory ‘/var/www/flarum/‘ and directories for Composer ‘/var/www/.cache‘ and ‘/var/www/.config‘. Then, change the ownership of those directories to user ‘www-data‘.

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

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

Now move to the ‘/var/www/flarum/‘ directory and download the Flarum source code via the Composer command below.

cd /var/www/flarum/

sudo -u www-data composer create-project flarum/flarum .

You can see below the downloading process of the Flarum source code.

<img alt="downloading flarum" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/12-download-flarum.png6635160e7205b.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="450" loading="lazy" src="data:image/svg xml,” width=”750″>

After the download process is complete, run the following ‘ls‘ command to check the Flarum source code.

ls -ah

You should see the downloaded Flarum source code like the following:

<img alt="flarum source code" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/13-flarum-source-code.png6635160e9e55d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="92" loading="lazy" src="data:image/svg xml,” width=”750″>

Setting up Apache virtual host for Flarum

After downloading Flarum, you need to create a new Apache virtual host. So be sure that you have prepared your domain name for the Flarum installation.

Before creating a virtual host, run the following command to enable Apache modules ‘ssl‘, ‘rewrite‘, and ‘headers‘.

sudo a2enmod ssl rewrite headers

<img alt="enable modules" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/14-enable-modules.png6635160ec3cb7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="276" loading="lazy" src="data:image/svg xml,” width=”696″>

Now create a new virtual host configuration ‘/etc/apache2/sites-available/flarum.conf‘ using the following nano editor command.

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

Insert the configuration below, and make sure to change the ServerName option with your domain name, and the path of the Document-Root directory for your Flarum installation.



ServerAdmin [email protected]

DocumentRoot /var/www/flarum/public

ServerName forum.hwdomain.io



Options FollowSymlinks

AllowOverride All

Require all granted

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined



RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*) index.php [PT,L]



When finished, save the file and exit the editor.

Next, run the command below to activate the virtual host file ‘flarum.conf’ and verify your Apache syntax.

sudo a2ensite flarum.conf

sudo apachectl configtest

You should have an output ‘Syntax OK‘ when you have proper Apache configuration.

<img alt="setup vhost" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/15-setup-apache-virtual-host.png6635160ee4ba2.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="305" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, run the following command to restart the Apache web server and apply the new Flarum virtual host configuration. With this, your Flarum should be accessible.

sudo systemctl restart apache2

Securing Flarum with HTTPS

If you’re running Flarum on a public domain, you can secure it with HTTPS using Certbot and Letsencrypt certificates. If you’re using a local domain, you can use Self-Signed certificates.

Install Certbot and the Certbot Apache plugin with the command below. Type Y to confirm the installation.

sudo apt install certbot python3-certbot-apache

Now execute the following ‘certbot’ command to generate SSL/TLS certificates for your Flarum installation. Be sure to change the details of the domain name and email address with your information.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d forum.hwdomain.io

Once the process is complete, your Flarum installation should be secured with HTTPS. And your SSL/TLS certificates should be available in the ‘/etc/letsencrypt/live/domain.com‘ directory.

Installing Flarum

Open your web browser and visit your domain name such as https://forum.hwdomain.io/. If your configuration is successful, you should get the Flarum installation wizard.

Input your forum title, details of the MariaDB database, user, and password. Then, input details admin user, email, and password for your new Flarum installation.

Click the ‘Install Flarum‘ button to continue the installation.

<img alt="install flarum" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/1-install-flarum.png6635160f1065c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="726" loading="lazy" src="data:image/svg xml,” width=”750″>

Once the installation is complete, you will be shown the Flarum administration dashboard like the following:

<img alt="flarum installed" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/2-flarum-installed.png6635160f3b097.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="324" loading="lazy" src="data:image/svg xml,” width=”750″>

Now click on your user icon and select Administration. This will show you details of your Flarum installation.

As you can see below the Flarum 1.8.5 is installed with PHP 8.3 and MariaDB server 10.11.

<img alt="admin dashboard flarum" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/3-admin-dashboard.png6635160f5d7b7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="497" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

Congratulations! You have now completed the installation of Flarum on Ubuntu 24.04. You have Flarum running with the LAMP Stack (Linux, Apache, MySQL/MariaDB, and PHP), you also secured Flarum with HTTPS via Certbot and Letsencrypt.