Sunday, May 19, 2024
HomeHow toHow to Install Flarum Next Generation Forum on Ubuntu 24.04

How to Install Flarum Next Generation Forum on Ubuntu 24.04

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

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.

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

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

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

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.

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;

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.

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.

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:

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

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.

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/flarum/public
ServerName forum.hwdomain.io

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

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

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

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.

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.

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

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.

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.


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here


Most Popular