How to Install Flarum on Ubuntu 23.10

Flarum is a free, open-source forum software built with PHP and Laravel. It's designed to be a modern, fast, and user-friendly alternative to traditional forum platforms. Flarum offers features such as real-time discussions, an extensible and flexible architecture, and a responsive design.

Pre-requisites :

  • A system with Ubuntu 23.10 installed and running.

  • root access to the system.

  • To install Flarum on an Ubuntu 23.10 server, you'll need a web server, PHP, a database, and Composer, a PHP dependency manager. For that, you can install LAMP (Linux, Apache, MySQL or MariaDB, PHP) stack by refering to one of our guides on installing the LAMP Stack (Apache, MariaDB, and PHP).

Login to the Ubuntu 23.10 server and update the package repository information.

apt update 
apt upgrade

Create a Flarum Database

mysql

Create database and user with the below command.

Replace the password with a strong and secure password.

CREATE DATABASE flarum;
CREATE USER 'flarum'@'localhost' IDENTIFIED BY 'password';

Grant all the privileges to the flarum database using the below command,

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

Flush the privileges and exit,

FLUSH PRIVILEGES;

EXIT;    

Install Composer

Install composer using below command,

curl -s https://getcomposer.org/installer | php

Output:

root@vps:~# curl -s https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 2.6.5) successfully installed to: /root/composer.phar
Use it: php composer.phar

root@vps:~#

Move Composer binary file to the /usr/local/bin/ directory with the following command,

 mv composer.phar /usr/local/bin/composer

Verify Composer version using below command,

composer -V

Output:

root@vps:~# composer -V
Composer version 2.6.5 2023-10-06 10:11:52
root@vps:~#

Install Flarum

Need to create directory for Flarum inside Apache web directory,

mkdir /var/www/html/flarum

Go to created directory /var/www/html/flarum

cd /var/www/html/flarum

Download the latest version of Flarum using Composer,

composer create-project flarum/flarum . --stability=beta

Install all PHP dependencies,

composer install

Change the ownership of Flarum to www-data and set permissions using below command,

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

Configure Flarum with Apache.

Create Apache virtual host configuration file for host Flarum,

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

Replace (flarum.domainhere.info) with (actual domain name).

Add the following lines,

 <VirtualHost *:80>
     ServerAdmin flarum.domainhere.info
     DocumentRoot /var/www/html/flarum/public
     ServerName flarum.domainhere.info
     DirectoryIndex index.php
     <Directory /var/www/html/flarum/public/>
    Options +FollowSymLinks
    AllowOverride All
    Order allow,deny
    allow from all
     </Directory>
    </VirtualHost>

Enable the Flarum virtual host and Apache rewrite module using the below command,

a2ensite flarum

a2enmod rewrite

Restart Apache serving to apply the changes,

systemctl restart apache2

systemctl status apache2

Output:

root@vps:/var/www/html/flarum# systemctl restart apache2
root@vps:/var/www/html/flarum#
root@vps:/var/www/html/flarum#     systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
     Active: active (running) since Thu 2023-10-19 17:57:08 UTC; 3s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 27211 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 27217 (apache2)
      Tasks: 6 (limit: 4563)
     Memory: 13.6M
        CPU: 98ms
     CGroup: /system.slice/apache2.service
             ├─27217 /usr/sbin/apache2 -k start
             ├─27218 /usr/sbin/apache2 -k start
             ├─27219 /usr/sbin/apache2 -k start
             ├─27220 /usr/sbin/apache2 -k start
             ├─27221 /usr/sbin/apache2 -k start
             └─27222 /usr/sbin/apache2 -k start

Oct 19 17:57:08 vps.server.com systemd[1]: Starting apache2.service - The Apache HTTP Server...
Oct 19 17:57:08 vps.server.com systemd[1]: Started apache2.service - The Apache HTTP Server.
root@vps:/var/www/html/flarum#

Secure Flarum with Let's Encrypt SSL

First, install the Certbot Let's Encrypt client using the below command,

apt-get install python3-certbot-apache -y

Run the below command to install Let's Encrypt SSL for Flarum Site,

 certbot --apache -d flarum.domainhere.info

You will be asked to provide your email address and accept the terms,

root@vps:/var/www/html/flarum# certbot --apache -d flarum.domainhere.info
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): testuser@email.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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
Account registered.
Requesting a certificate for flarum.domainhere.info

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/flarum.domainhere.info/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/flarum.domainhere.info/privkey.pem
This certificate expires on 2024-01-17.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for flarum.domainhere.info to /etc/apache2/sites-available/flarum-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://flarum.domainhere.info

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
root@vps:/var/www/html/flarum#

Navigate your browser:

https://flarum.domainhere.info

Replace flarum.domainhere.info with your actual_domain_name.

image

Fill the Database details and create the Admin account,

image

Click on install, and you'll get the dashboard like below,

image

Done.