Wednesday, July 3, 2024
HomeOperating SystemsUbuntuHow To Setup Flarum discussion forum on Ubuntu 22.04

How To Setup Flarum discussion forum on Ubuntu 22.04

A discussion platform is a recommended feature for any website. It allows users to interact with each other by sharing their thoughts, opinions, and experiences about a particular topic or subject. It is a type of online forum where users can create and participate in discussions on a website. Discussion platforms can come in different forms, such as chat rooms, message boards, comment sections, or social media-like platforms.

Discussion platforms are often used on websites that focus on community building, news or current events, education, or any topic that requires feedback, opinions, or discussions from the users. This can form a basic way to engage users and create a sense of community around a website. However, it also requires proper moderation to ensure that the discussions remain respectful, on-topic, and free from any offensive or inappropriate content.

Flarum is open-source forum software that allows users to create discussion forums on their websites. It is designed to be fast, easy to use, and highly customizable. Flarum is built using PHP and the Laravel framework and uses modern web technologies such as HTML5 and CSS3.

Flarum is licensed under the MIT License, which means that it is free to use, modify, and distribute. It has a strong community of developers and users who actively contribute to its development and offer support through forums and other channels.

Flarum offers features that include:

  • Modern and responsive user interface: It has a clean, modern, and responsive user interface that adapts to different screen sizes, making it easy to use on any device.
  • Extensions and plugins: It offers a rich set of extensions and plugins that can be used to extend the functionality of the forum. Users can choose from a range of free and paid plugins that can add features such as social login, SEO optimization, and more.
  • User profiles and notifications: Flarum allows users to create profiles, view their activity, and receive notifications when someone replies to their posts or mentions them in a discussion.
  • Search functionality: It has a powerful search engine that allows users to search for discussions, posts, and users.
  • Multi-language support: It supports multiple languages, making it easy to create forums in different languages.
  • Moderation tools: It offers a range of moderation tools that allow administrators to manage user accounts, monitor discussions, and moderate content.
  • Security: It is designed with security in mind and has features such as password hashing, CSRF protection, and XSS prevention to keep the forum secure.

This guide demonstrates how to setup the Flarum discussion forum on Ubuntu 22.04.

Getting Started

Flarum requires the following:

  • Apache (with mod_rewrite enabled) or Nginx
  • PHP 7.3+ with the following extensions: curl, dom, fileinfo, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip
  • MySQL 5.6+/8.0.23+ or MariaDB 10.0.5+
  • SSH (command-line) access to run Composer

We will walk through all the installation together.

#1. Install PHP and Configure on Ubuntu 22.04

One of the requirements of Flarum is PHP 7.3 and above with several other extensions. Our page provides the below guide to help you install PHP on Ubuntu 22.04.

sudo apt update
sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.2
sudo apt install php8.1-{bcmath,xml,fpm,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi}

Check the installed PHP version

$ php -v
PHP 8.2.6 (cli) (built: May 12 2023 06:24:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.6, Copyright (c), by Zend Technologies

View the installed extensions:

$ php -m
[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
........

Export your PHP version. For example

export PHP=8.2

Once installed, make PHP configurations as shown:

sudo apt install apache2 libapache2-mod-php8.2
sudo vim /etc/php/$PHP/apache2/php.ini

Make the below adjustments to the file:

memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 150M
allow_url_fopen = On
file_uploads = On

Save the file and exit

#2. Install PHP Composer on Ubuntu 22.04

PHP composer is used to install Flarum. We need to ensure that it is installed on Ubuntu 22.04. First, pull the installer:

wget -O composer-setup.php https://getcomposer.org/installer

Run the global installation:

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

Sample output:

All settings correct for using Composer
Downloading...

Composer (version 2.5.5) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Verify the installation:

$ composer -V
Composer version 2.5.5 2023-03-21 11:50:05

#3. Install MariaDB on Ubuntu 22.04

For this guide, we will use MariaDB as the database server.

sudo apt install mariadb-server

Once installed, create a database for Flarum. Access the MariaDB shell:

sudo mariadb -u root

Now create the database and user:

CREATE DATABASE flarum_db;
CREATE USER 'flarum_user'@'localhost' IDENTIFIED BY 'StrongDBPassw0rd';
GRANT ALL PRIVILEGES ON flarum_db.* TO 'flarum_user'@'localhost';
FLUSH PRIVILEGES;
EXIT

#4. Install Flarum On Ubuntu 22.04

Create a working directory for Flarum On Ubuntu 22.04 in the Apache web root directory:

 sudo mkdir /var/www/html/flarum

Navigate to the created directory:

cd /var/www/html/flarum

Download the latest Flarum version using Composer.

sudo composer create-project flarum/flarum .

Proceed as shown below:

Continue as root/super user [yes]? yes
Creating a "flarum/flarum" project at "./"
Info from https://repo.packagist.org: #StandWithUkraine
Installing flarum/flarum (v1.7.0)
.....
  - Installing flarum/tags (v1.7.1): Extracting archive
64 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating autoload files
73 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found

Set the ownership of the directory to www-data and assign the required permissions:

sudo chown -R www-data:www-data /var/www/html/flarum/
sudo chmod -R 755 /var/www/html/flarum/

#5. Configure Apache for Flarum

We want to configure Apache to serve Flarum. To do so, create a virtual host file as shown:

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

In the file, add the below lines:

<VirtualHost *:80>
 DocumentRoot /var/www/html/flarum/public
 ServerName flarum.neveropen.co.za
 DirectoryIndex index.php

 <Directory /var/www/html/flarum/public/>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
 </Directory>

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

</VirtualHost>

Save the file and enable the site:

sudo a2ensite flarum

Now enable the rewrite module for Apache:

sudo a2enmod rewrite

Restart the service:

sudo systemctl restart apache2

If you have a firewall enabled, allow HTTP and HTTPS through it:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

#6. Access Web UI and Finish Installation

We are now set to access the Flarum web UI and complete the installation. To access the page, use the URL http://domain_name

Setup Flarum discussion forum on Ubuntu 22.04

On the above page, provide the s=tittle, database name, username and password. You also need to create the admin user. Once filled, click install and you will the redirected to the below page.

Setup Flarum discussion forum on Ubuntu 22.04 1

You can now start a discussion on Flarum

#7. (Optional) Secure Flarum with Let’s Encrypt SSL

It is always important to protect your traffic to ensure that your creds and other important info do not travel through an unprotected wire. To do so, we will configure HTTPS for our site. To proceed with this step, you need to have a Fully Qualified Domain Name(FQDN).

First, install the required packages:

sudo apt-get install python3-certbot-apache -y

Now create free SSL certs for your Domain name using Let’s Encrypt as shown:

sudo certbot --apache -d your-domain-name.com

Replace your-domain-name.com appropriately and proceed as shown:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

(Y)es/(N)o: Y

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for your-domain-name.com
Waiting for verification...
Cleaning up challenges

Created an SSL vhost at /etc/apache2/sites-available/flarum-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/flarum-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/flarum-le-ssl.conf

Choose to redirect HTTP traffic to HTTPS:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting vhost in /etc/apache2/sites-enabled/flarum.conf to ssl vhost in /etc/apache2/sites-available/flarum-le-ssl.conf

After this, you will have SSL certs generated for your domain name. You need to make some configurations to your config:

sudo vim /var/www/html/flarum/config.php

In the file, find the URL part and configure it to use HTTPS and your domain name:

'url' => 'https://your-domain-name.com',

Save the file and proceed to access your site over HTTPS.

Setup Flarum discussion forum on Ubuntu 22.04 2

Verdict

We have successfully walked through how to install the Flarum discussion forum on Ubuntu 22.04. I hope this was informative.

See more:

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

Most Popular

Recent Comments