How to Install Flarum Forum on Ubuntu 20.04

Flarum is a free, open-source and next-generation forum application that helps you to build your own online discussion forum. It is written in PHP, simple, fast and easy to deploy. It provides a flexible architecture, powerful extension APT and all the features you need to run a successful community. Flarum looks and feels great out of the box. The user interface is streamlined so you can spend less time clicking and more time talking.

In this tutorial, we will explain how to install Flarum forum with Apache and Let's Encrypt SSL on Ubuntu 20.04 server.

Prerequisites

  • A server running Ubuntu 20.04.
  • A valid domain name pointed with your server IP.
  • A root password is configured the server.

Getting Started

First, it is always recommended to update your system packages to the latest version. You can update them using the following command:

apt-get update -y

Once all packages are updated, you can proceed to the next step.

Install LAMP Server

Flarum is written in PHP, runs on the web server and uses MySQL/MariaDB as a database backend. So you will need to install the LAMP stack in your system. You can install it with the following command:

apt-get install apache2 mariadb-server php7.4 libapache2-mod-php7.4 php7.4-common php7.4-mbstring php7.4-xmlrpc php7.4-soap php7.4-mysql php7.4-gd php7.4-xml php7.4-curl php7.4-cli php7.4-zip php7.4-tokenizer wget unzip curl git -y

Once all the packages are installed, edit the php.ini file and tweak some settings:

nano /etc/php/7.4/apache2/php.ini

Modify the following lines:

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_file_size = 150M
max_execution_time = 450
date.timezone = Asia/Kolkata

Save and close the file when you are finished.

Create a Flarum Database

Next, you will need to create a database and user for Flarum. First, log into the MariaDB shell with the following command:

mysql

Once login, create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE flarum;
MariaDB [(none)]> CREATE USER 'flarum'@'localhost' IDENTIFIED BY 'password';

Next, grant all the privileges to the flarum database with the following command:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON flarum.* TO 'flarum'@'localhost';

Next, flush the privileges and exit from the MariaDB with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once you are finished, you can proceed to the next step.

Install Composer

Next, you will need to install Composer in your system. Composer is a dependency manager for PHP used to install all dependencies required for PHP project.

You can install the Composer with the following command:

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

You should get the following output:

All settings correct for using Composer
Downloading...

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

Next, move the Composer binary to the /usr/local/bin/ directory with the following command:

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

Next, verify the installed version of the Composer with the following command:

composer -V

You should see the following output:

Composer version 1.10.10 2020-08-03 11:35:19

Install Flarum

First, create a directory for Flarum inside the Apache web root directory with the following command:

mkdir /var/www/html/flarum

Next, change the directory to flarum and download the latest version of Flarum using the Composer as shown below:

cd /var/www/html/flarum
composer create-project flarum/flarum . --stability=beta

Next, install all PHP dependencies using the following command:

composer install

Once all the dependencies are installed, change the ownership of the Flarum to www-data and give proper permission with the following command:

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

Once you are finished, you can proceed to the next step.

Configure Apache for Flarum

Next, you will need to create an Apache virtual host configuration file to host Flarum. You can create it with the following command:

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

Add the following lines:

<VirtualHost *:80>
 ServerAdmin [email protected]
 DocumentRoot /var/www/html/flarum/public
 ServerName flarum.linuxbuz.com
 DirectoryIndex index.php
 <Directory /var/www/html/flarum/public/>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
 </Directory>
 ErrorLog /var/log/apache2/flarum-error_log
 CustomLog /var/log/apache2/flarum-access_log common
</VirtualHost>

Save and close the file when you are finished. Then, enable the Flarum virtual host and Apache rewrite module with the following command:

a2ensite flarum
a2enmod rewrite

Finally, restart the Apache service to apply the changes:

systemctl restart apache2

You can also verify the status of the Apache using the following command:

systemctl status apache2

You should get the following output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-08-23 09:57:11 UTC; 2min 44s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 27164 (apache2)
      Tasks: 6 (limit: 2353)
     Memory: 12.3M
     CGroup: /system.slice/apache2.service
             ??27164 /usr/sbin/apache2 -k start
             ??27165 /usr/sbin/apache2 -k start
             ??27166 /usr/sbin/apache2 -k start
             ??27167 /usr/sbin/apache2 -k start
             ??27168 /usr/sbin/apache2 -k start
             ??27169 /usr/sbin/apache2 -k start

Aug 23 09:57:11 ubuntu2004 systemd[1]: Starting The Apache HTTP Server...

Secure Flarum with Let's Encrypt SSL

It is always recommended to secure your website with Let's Encrypt free SSL. First, install the Certbot Let's Encrypt client with the following command:

apt-get install python3-certbot-apache -y

Once installed, run the following command to install Let's Encrypt SSL for your Flarum website:

certbot --apache -d flarum.linuxbuz.com

You will be asked to provide your valid email address and accept the term of service as shown below:

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 flarum.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/flarum-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/flarum-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/flarum-le-ssl.conf

Next, choose whether or not to redirect HTTP traffic to HTTPS as shown below:

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

Type 2 and hit Enter to install the SSL certificate for your website. Once the installation is completed, you should get the following output:

Redirecting vhost in /etc/apache2/sites-enabled/flarum.conf to ssl vhost in /etc/apache2/sites-available/flarum-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://flarum.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=flarum.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/flarum.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/flarum.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-11-21. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Access Flarum Forum

At this point, Flarum is installed, configured and secured with Let's Encrypt SSL. Now, open your web browser and access the Flarum using the URL https://flarum.linuxbuz.com. You will be redirected to the following page:

Provide your forum name, database name, username, password, admin username, password, email address and click on the Install Flarum button. Once the installation has been completed, you will be redirected to the Flarum dashboard as shown below:

Conclusion

Congratulations! you have successfully installed Flarum forum with Apache and Let's Encrypt SSL on Ubuntu 20.04 server. You can now host your own community forum easily with Flarum. Feel free to ask me if you have any questions.

Share this page:

2 Comment(s)