Flarum is the next-generation forum software that makes online discussions fun. It is simple, fast, and free. The source code of Flarum is hosted on GitHub. This guide will walk you through the installation process of Flarum on an Ubuntu system with PHP, MySQL as a database, and Nginx as a web server.

Requirements

Before you install Flarum, it is important to check whether your server meets the requirements. To run Flarum, you need:

  • Apache (with mod_rewrite enabled) or Nginx. Nginx is used in this course.
  • PHP 7.1 with the following extensions: dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer.
  • MySQL version 5.6 or higher or MariaDB version 10.0.5 or higher. MySQL is used in this tutorial.

Prerequisites

  • An Ubuntu 18.04 LTS operating system.
  • A non-root user with sudo rights.

First steps

Check your Ubuntu version:

lsb_release -ds
# Ubuntu 18.04.3 LTS

Set up the time zone:

sudo dpkg-reconfigure tzdata

Update the packages of your operating system (software). This is an important first step because it ensures that you have the latest updates and security fixes for the standard software packages of your operating system:

sudo apt update && sudo apt upgrade -y

Install some important packages that are necessary for basic Ubuntu operating system management:

sudo apt install -y curl wget vim git unzip socat bash-completion apt-transport-https

Step 1 – Install PHP and the necessary PHP modules

Install PHP and the necessary PHP extensions:

sudo apt install -y php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-mbstring php7.2-gd php7.2-xml php7.2-mysql php7.2-curl

Check the PHP version:

php --version
# PHP 7.2.19-0ubuntu0.18.04.1 (cli) (built: Jun  4 2019 14:48:12) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
#     with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Step 2 – Install MySQL and create a Flarum database

Install MySQL:

sudo apt install -y mysql-server

Check the MySQL version:

mysql --version
# mysql  Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using  EditLine wrapper

Run the script mysql_secure_installation to increase the security of your MySQL installation:

sudo mysql_secure_installation

Log in to MySQL as root user:

sudo mysql -u root -p
# Enter password:

Create a new MySQL database and a database user and memorize the access data:

mysql> CREATE DATABASE dbname;
mysql> GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> quit

NOTE: Replace dbname and username with suitable names for your installation. Replace password with a secure password.

Step 3 – Install the acme.sh client and obtain a Let’s Encrypt certificate (optional)

It is not necessary to secure your website with HTTPS, but it is good practice to protect your website traffic. To get a TLS certificate from Let’s Encrypt, we’ll use the acme.sh client. Acme.sh is a simple UNIX shell software that allows you to obtain TLS certificates from Let’s Encrypt without any dependencies.

Download and install acme.sh:

sudo su - root
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh 
./acme.sh --install --accountemail [email protected]
source ~/.bashrc
cd ~

Check the version of acme.sh:

acme.sh --version
# v2.8.2

Obtain RSA and ECC/ECDSA certificates for your domain/hostname:

# RSA 2048
acme.sh --issue --standalone -d example.com --keylength 2048
# ECDSA
acme.sh --issue --standalone -d example.com --keylength ec-256

If you want fake certificates for testing, you can add the flag --staging to the above commands.

After you have executed the above commands, your certificates and keys will be located in:

  • For RSA: /home/username/example.com directory.
  • For ECC/ECDSA: /home/username/example.com_ecc directory.

To list your issued certificates, you can do the following:

acme.sh --list

Create a directory to store your certificates. We will use the /etc/letsencrypt directory.

mkdir -p /etc/letsecnrypt/example.com
sudo mkdir -p /etc/letsencrypt/example.com_ecc

Install/copy the certificates to /etc/letsencrypt directory.

# RSA
acme.sh --install-cert -d example.com --cert-file /etc/letsencrypt/example.com/cert.pem --key-file /etc/letsencrypt/example.com/private.key --fullchain-file /etc/letsencrypt/example.com/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"
# ECC/ECDSA
acme.sh --install-cert -d example.com --ecc --cert-file /etc/letsencrypt/example.com_ecc/cert.pem --key-file /etc/letsencrypt/example.com_ecc/private.key --fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem --reloadcmd "sudo systemctl reload nginx.service"

All certificates are automatically renewed every 60 days.

After you have received the certificates, leave the root user and return to the normal sudo user:

exit

Step 4 – Install and configure Nginx

Install Nginx:

sudo apt install -y nginx

Check the version:

sudo nginx -v
# nginx version: nginx/1.14.0 (Ubuntu)

Configure Nginx for Flarum. Start sudo vim /etc/nginx/sites-available/flarum.conf and fill the file with the following configuration:

server {

  listen [::]:443 ssl;
  listen 433 ssl;
  listen [::]:80;
  listen 80;
  
  server_name example.com;
  root /var/www/flarum/public;
  
  index index.php;
  
  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }
  
  location ~* .php$ {
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }

}

Save the file and close your editor.

Activate the new flarum.conf configuration by linking the file to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/flarum.conf /etc/nginx/sites-enabled/

Test the configuration:

sudo nginx -t

Reload Nginx:

sudo systemctl reload nginx.service

Step 5 – Install Composer

Download Composer, the dependency manager for PHP, and install it:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

Check the version:

composer --version
# Composer version 1.9.1 2019-11-01 17:20:17

Step 6 – Install Flarum

Create a document root directory where Flarum should be installed:

sudo mkdir -p /var/www/flarum

Change the ownership of the directory /var/www/flarum to johndoe:

sudo chown -R johndoe:johndoe /var/www/flarum

Navigate to the document root directory:

cd /var/www/flarum

Download the latest version of Flarum via composer:

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

NOTE: If you install Flarum via Composer, you may run out of disk space. If this happens, you will need to set up swap.

Change the ownership of the /var/www/flarum directory to www-data:

sudo chown -R www-data:www-data /var/www/flarum

Step 7 – Finish the installation

Open your website in a web browser and follow the on-screen instructions to complete the installation.

Set up your forum by entering your details below:

How to install Flarum Forum with Nginx on Ubuntu linux ubuntu

You will then be redirected to the Flarum forum frontend:

How to install Flarum Forum with Nginx on Ubuntu linux ubuntu

Links