In this tutorial, we'll learn how to install Flarum modern forum on AlmaLinux 9 and use Nginx as the web server, MariaDB as the database, and PHP via PHP-FPM.
Overview of Flarum
Flarum is a forum platform that combines simplicity, elegance, and modern technology. It offers a slick user interface and a powerful extension system, making it easy to customize and extend. Because it is lightweight, it typically requires fewer server resources than many other solutions, which translates to faster performance.
Why Flarum?
- Modern UI: Flarum has a mobile-friendly interface with smooth interactions.
- Customizable: A robust extension system lets you add features like social logins, SEO enhancements, and spam defenses.
- Community-Driven: A supportive community and a growing ecosystem of extensions.
Prerequisites
Before proceeding, make sure you have the following in place:
- A Fresh AlmaLinux 9 dedicated server or KVM VPS.
- Root or Sudo Privileges: You should have sudo privileges to install packages and make system-wide changes.
- A Valid Domain Name (Optional but Recommended)
Install Nginx Proxy Manager on AlmaLinux 9
1. Update Your System
Log in to your AlmaLinux 9 server via SSH.
Update the system packages to get the latest bug fixes and security patches:
sudo dnf update -y
Install Essential Packages
Install some useful utilities like wget, curl, or nano (for editing files):
sudo dnf install -y wget curl nano
These packages will help you download files, configure the system, and modify text files.
3. Install and Configure the PHP Environment
Flarum is built with PHP, so you’ll need to install PHP 8.0+ (the exact PHP version required may vary, but PHP 8.0 or 8.1 is recommended). We also need extensions like gd, mbstring, and xml for Flarum to function properly.
List available PHP modules
dnf module list php
If other versions are enabled, reset once and switch to the version
dnf module reset php
dnf module -y enable php:8.2
However, if the default AppStream repository contains the required PHP version, you can skip this step.
Install PHP with required extensions (the command below includes common Flarum requirements):
sudo dnf install -y php php-fpm php-cli php-common \
php-curl php-gd php-json php-mbstring \
php-mysqlnd php-xml php-zip php-opcache
Make sure php-fpm (the PHP FastCGI Process Manager) is included because we will be using Nginx, which doesn’t handle PHP on its own.
Configure PHP Settings
Flarum may need increased PHP memory limit and other tweaks. Open the php.ini configuration:
sudo nano /etc/php.ini
Look for and update the following values (if necessary):
memory_limit = 256M
upload_max_filesize = 50M
post_max_size = 50M
max_execution_time = 300
These settings ensure you can handle larger file uploads (like images) and avoid timeouts.
Modify PHP-FPM user
nano /etc/php-fpm.d/www.conf
find user and group and replace apache with nginx
user = nginx
group = nginx
Start and Enable PHP-FPM
sudo systemctl enable php-fpm
sudo systemctl start php-fpm
This ensures PHP-FPM starts when your server boots and is ready to handle PHP requests for Nginx.
4. Install and Secure MariaDB
MariaDB is a reliable and open-source database server. It is fully compatible with MySQL protocols and is widely used in web hosting environments.
Install MariaDB
sudo dnf install -y mariadb mariadb-server
Start and Enable MariaDB
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure MariaDB
Run the secure installation script to set the root password and remove some default options:
sudo mysql_secure_installation
You will be prompted to set a new MariaDB root password. Choose a strong one, then follow the prompts to remove anonymous users, disable remote root login, and remove the test database.
Create a Database and User for Flarum
Log in to the MariaDB console:
sudo mysql -u root -p
Create a new database (call it flarumdb or a name you prefer):
CREATE DATABASE flarumdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Create a dedicated user (for example, flarumuser) with a strong password:
CREATE USER 'flarumuser'@'localhost' IDENTIFIED BY 'your_strong_password';
Grant the user permissions on the flarumdb:
GRANT ALL PRIVILEGES ON flarumdb.* TO 'flarumuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Make sure you remember the database name, username, and password—Flarum will need them.
5. Install Composer
Flarum is distributed as a Composer project. Composer is a dependency manager for PHP that simplifies the process of installing and updating PHP packages.
Download and Install Composer
cd ~
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
rm composer-setup.php
Verify Installation
composer -V
You should see the Composer version output on the screen.
6. Configure Firewall and SELinux
If you have enabled firewall and selinux, follow these steps
Add HTTP AND HTTPS ports in firewall
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --reload
We might need to configure SELinux to allow the web server to write to the directory.
chcon -R -t httpd_sys_rw_content_t /var/www/flarum/
7. Install Flarum
We will now install Flarum in the /var/www/flarum directory. You can adapt this location to your preference.
Create the Directory for Flarum
sudo mkdir -p /var/www/flarum
cd /var/www/flarum
By assigning ownership to your user, you can run composer commands without permission issues.
Install Flarum Using Composer
composer create-project flarum/flarum:^1.8.0 .
The .
at the end tells Composer to install Flarum in the current directory (/var/www/flarum
).
If you wish to install and update extensions from the admin dashboard, you need to also install the Extension Manager extension.
composer require flarum/extension-manager:"*"
Set Correct Permissions
After installation completes, set the correct file permissions:
sudo chown -R nginx:nginx /var/www/flarum
This ensures Nginx and PHP-FPM can read and write to Flarum’s directories.
8. Configure Nginx for Flarum
Nginx will serve as our web server. We need to create a configuration that points to the Flarum directory and configures PHP-FPM handling.
Install Nginx
sudo dnf install -y nginx
Create a New Nginx Server Block
Create a file named something like flarum.conf
in /etc/nginx/conf.d
:
sudo nano /etc/nginx/conf.d/flarum.conf
Place the following basic configuration inside it:
server {
listen 80;
server_name your_domain_or_IP;
root /var/www/flarum/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Explanation:
- listen 80; means the server block listens on port 80 (HTTP).
- server_name your_domain_or_IP; should match your domain or server’s IP address.
- root /var/www/flarum/public; is set to Flarum’s public directory.
- location / block uses try_files to rewrite requests to index.php.
- location ~ \.php$ block ensures all PHP files are passed to PHP-FPM.
Check Nginx Configuration Syntax
sudo nginx -t
If there are no errors, proceed.
Enable and Restart Nginx
sudo systemctl enable nginx
sudo systemctl restart nginx
9. (Optional) Enable HTTPS with Let’s Encrypt
It’s highly recommended to serve your forum over HTTPS. Let’s Encrypt provides free SSL certificates.
Install Certbot
sudo dnf install -y certbot python3-certbot-nginx
Obtain a Certificate
Run certbot with the Nginx plugin:
sudo certbot --nginx -d your_domain_or_IP
Follow the prompts. Certbot will automatically configure your Nginx server block for SSL.
Auto-Renew Certificate
Certbot sets up a cron job automatically on modern distributions, ensuring your certificate is renewed before expiry.
10. Finalize Flarum Installation in Browser
With all services running, you can finalize your Flarum installation in a web browser.
Open Your Forum URL
In your browser, navigate to http://your_domain_or_IP
. If you set up SSL, use https://your_domain_or_IP
.
You should see Flarum’s Installation Page.
Database Configuration
Enter the database name, user, and password you created earlier for MariaDB.
Provide a table prefix if you want (optional), or leave it blank.
Administrator User Setup
Choose an admin username, email, and secure password.
Provide a Title for your forum (e.g., “My Awesome Forum”).
Hit ‘Install’
Flarum will install tables in your database and generate a config file. This might take a moment.
Post-Installation
- Log in to the admin area (click “Administration” in the user dropdown) to configure:
- Extensions (enable/disable them for added functionality).
- Appearance (upload a logo or change the base color scheme).
- Settings like mail configuration, forum description, and more.
11. Maintenance Tips
Updating Flarum: You can update Flarum and its extensions via Composer:
cd /var/www/flarum
composer update
sudo php flarum migrate
sudo php flarum cache:clear
Backing Up Database: Regularly back up your database using mysqldump:
mysqldump -u flarumuser -p flarumdb > flarumdb_backup.sql
Monitoring Logs:
- Check Nginx logs in /var/log/nginx/error.log or /var/log/nginx/access.log.
- Check PHP-FPM logs in /var/log/php-fpm/error.log.
- Flarum also generates its own logs in /var/www/flarum/storage/logs.
Conclusion
In this tutorial, we've learnt how to install Flarum modern forum on AlmaLinux 9. with Nginx and MariaDB. From setting up PHP-FPM to configuring your database and Nginx, you’ve gone through the essential steps to get your modern forum online.
Flarum’s intuitive interface and rich extension ecosystem make it a great choice for building a thriving community. Remember to keep your system, Flarum core, and extensions updated to stay secure and enjoy the latest features. Now that your forum is live, you can start exploring extensions, customizing your design, and inviting members to join the conversation.
Congratulations on your new Flarum forum!