Jump to content

How to Install Flarum on an Ubuntu Server – A Complete Guide

Featured Replies

Posted
  • Administrators
comment_283

flarum.webp

Flarum is a lightweight and modern open-source forum software built with PHP and MySQL. It supports extensions, has a clean UI, and is easy to set up.

This guide will walk you through installing Flarum from scratch on an Ubuntu server, configuring Nginx, PHP, and MariaDB, and setting up HTTPS for secure access.


1. System Requirements

Before installing Flarum, ensure your server meets the following requirements:

  • Operating System: Ubuntu 20.04 / 22.04

  • Web Server: Nginx (recommended)

  • PHP Version: ≥ 7.4 (PHP 8.1+ recommended)

  • Database: MySQL or MariaDB (MariaDB recommended)

  • Composer: For managing PHP dependencies

  • Shell Access: SSH access to the server


2. Update the System

Before proceeding, update your system packages:

sudo apt update && sudo apt upgrade -y

Explanation:

  • sudo apt update: Updates package lists without installing anything.

  • sudo apt upgrade -y: Upgrades all installed packages (-y automatically confirms).


3. Install PHP and Required Extensions

Flarum requires PHP and several extensions. Install them using:

sudo apt install php php-cli php-fpm php-mysql php-json php-mbstring php-xml php-curl php-zip -y

Explanation:

  • php-cli: PHP command-line interface.

  • php-fpm: FastCGI Process Manager for PHP (required for Nginx).

  • php-mysql: Enables MySQL support.

  • php-json: Handles JSON data.

  • php-mbstring: Multi-byte string support.

  • php-xml: Parses XML data.

  • php-curl: Supports HTTP requests.

  • php-zip: Handles ZIP file operations.

Check PHP Version:

php -v

If your PHP version is below 7.4, update it with:

sudo add-apt-repository ppa:ondrej/php -y sudo apt update sudo apt install php8.1 php8.1-fpm php8.1-mysql php8.1-mbstring php8.1-xml php8.1-curl php8.1-zip -y

4. Install Composer (PHP Dependency Manager)

Flarum is installed via Composer. Install it with:

curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer

Check Composer Version:

composer --version

5. Install Nginx (Web Server)

We will use Nginx as the web server.

Install Nginx

sudo apt install nginx -y

Start Nginx

sudo systemctl start nginx sudo systemctl enable nginx

Check Nginx Status

sudo systemctl status nginx

Verify Installation:
Open your browser and visit your server's IP address. If you see Welcome to Nginx!, the installation is successful.

http://your_server_ip

6. Install MariaDB (Database Server)

MariaDB is a MySQL-compatible database server. We will use it for Flarum.

Install MariaDB

sudo apt install mariadb-server -y

Start and Enable MariaDB

sudo systemctl start mariadb sudo systemctl enable mariadb

Secure MariaDB Installation

Run the following command and follow the prompts to improve security:

sudo mysql_secure_installation
  • Set a root password

  • Remove anonymous users

  • Disallow root remote login

  • Remove the test database

  • Reload privileges

Create a Database for Flarum

sudo mysql -u root -p

After entering the MySQL root password, run:

CREATE DATABASE flarum; CREATE USER 'flarumuser'@'localhost' IDENTIFIED BY 'yourpassword'; GRANT ALL PRIVILEGES ON flarum.* TO 'flarumuser'@'localhost'; FLUSH PRIVILEGES; EXIT;

Explanation:

  • Database Name: flarum

  • Username: flarumuser

  • Password: yourpassword (change this)


7. Install Flarum

Navigate to the Web Root Directory

cd /var/www/

Download and Install Flarum via Composer

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

Set Correct Permissions

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

8. Configure Nginx

Create a new Flarum configuration file:

sudo nano /etc/nginx/sites-available/flarum

Add the following content:

server { listen 80; server_name yourdomain.com; root /var/www/; index index.php; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }

Enable the Configuration:

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

Test Nginx Configuration:

sudo nginx -t

If no errors, restart Nginx:

sudo systemctl restart nginx

9. Access the Installation Page

Open your browser and visit:

http://yourdomain.com

Follow the setup wizard:

  • Enter Database Details

  • Create Admin Account

  • Complete Installation


10. Secure Flarum with HTTPS (SSL)

Use Let's Encrypt to obtain a free SSL certificate:

sudo apt install certbot python3-certbot-nginx -y sudo certbot --nginx -d yourdomain.com

Follow the prompts. Your site will now be accessible via HTTPS.


11. Installation Complete

🎉 Congratulations! Flarum is successfully installed! 🎉

Visit your forum:

https://yourdomain.com

Now you can explore and configure Flarum!


Summary

This guide covered: System Update
Installing PHP, Composer, Nginx, MariaDB
Setting Up Flarum and Enabling HTTPS


Related tutorial

This is the plugin installation tutorial for Flarum:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...