Quickly Install Flarum Community on LEMP Stack along with WordPress

You can easily install Flarum forum program in a subdirectory on the LEMP Stack server along with WordPress running in the root folder. Just need to adjust the Nginx config with the correct location of index file.

I’m excited to share that I install Flarum community and launch our restoreBin explore forum — a community for exploring and discuss the awesome tips and solutions in Technology and Digital.

It’s powered by Flarum forum software (still in BETA) loaded on the fastest Nginx server along with WordPress blogging CMS running on the DigitalOcean cloud server. The best part, both platforms are sharing the same configurations and caching mechanism.

I struggled a lot while installing the Flarum forum, as their official installation doc is not very clear and detailed. It took me 2 days to complete the setup without disturbing my existing blogs. And yes – I have done it!

Here is how my setup looks like in on DigitalOcean server:

  • ~/ root folder
    • ~/var/www/demo/ Current WordPress installation
      • ~/var/www/demo/forum/ New Flarum installation

Also, both WordPress and Flarum share the same nginx.conf file which makes the configuration lot easier and secure. You can follow this detailed guide about WordPress on DigitalOcean cloud.

Let’s dive into installing the Flarum forum in Ubuntu Cloud Server —

Requirements to Install Flarum

Before we get started with the installation process, I’m assuming you already have a LEMP stack server configured. If not, then refer the guide to install.
Here are the basic requirements for Flarum forum program to run smoothly:

  • Linux OS – personally prefer Ubuntu
  • Nginx or Apache webserver
  • PHP 7.1+ with the following extensions: dom, gd, json, mbstring, OpenSSL, pdo_mysql, tokenizer
  • MySQL 5.6+ or MariaDB 10.0.5+
  • SSH (command-line) access to run Composer and installation
  • SFTP access with FileZilla or similar FTP client installed

My current LEMP Stack is configured with the latest of all the above requirements running on MySQL database and Nginx web server. You can follow this guide for details – Powerful LEMP Stack.

Adding a Swap Space on Ubuntu Server

Installing Composer and Flarum program need extra RAM. The $5 DigitalOcean has 1GB RAM size which is enough to run the forum software, however, it needs extra processing memory when installing the Flarum.

If you’re running on and over 2GB RAM server, you can skip adding the Swap file. For less than 2 GB RAM server, Swapfile is a must.

Swapfile is a piece of hard disk space that will act as a RAM whenever there is a demand for memory to execute certain programs. We will be using this Swapfile to install Flarum on our Cloud Server.

Creating the Swap space

Run the following command to verify if you already have a swap file:

free -h

If not, then allocate a separate partition space in the hard disk for the swap file. The general thumb rule about swapfile is to be double the actual RAM size. In my case, I have the 1GB RAM server, so I’ll be creating the Swap file of 2GB size.

sudo fallocate -l 2G /swapfile

We can cross verify if the correct amount of partition is allocated using the below command:

ls -lh /swapfile

Now let’s make the file available only to root user.

sudo chmod 600 /swapfile

The output will show that root the user has read and write permissions.

Now mark the file as swap space by hitting below command:

sudo mkswap /swapfile

Finally, run the command to allow the system to utilize the swapfile.

sudo swapon /swapfile

Run the following command to verify the free space as the existence of swap space.

free -h

We have successfully, created the swap space that is valid until the next reboot. However, if we wan the swap space to be available even after a restart, we need to make some additional changes.

Run the following command to add the swap information into /etc/fstab file to make it permanent.

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

We have now successfully created the swap file space in a cloud server.

Tweaking the Swap Space

As mentioned that swap will be used when our server is running out of memory. This is a temporary solution at peak utilization hours, but using the swap file is quite ‘expensive’ as it degrades the overall server performance. Hence, we should generally avoid using swap space.

Also, by default, the system is set to use the swap file anywhere from 0 to 100%. However, we should limit this to lower value something which should be close to 10%.

To adjust the swap usage, we should adjust the swappiness value. Run the following command to set the swappiness value to 10.

sudo sysctl vm.swappiness=10

And next, add the following line of code into system configuration file to make these changes permanent and persist even after a reboot.

Edit the system configuration file using below command:

sudo nano /etc/sysctl.conf

And add the following line at the bottom.

vm.swappiness=10

Similarly, we should also adjust the cache pressure settings for the swap file. This will avoid heavy usage of swap space for any caching.

Run the flowing command to set the cache pressure to a maximum of 50%:

sudo sysctl vm.vfs_cache_pressure=50

Add and Tweak Swap File Space in Ubuntu

Again open the system configuration file:

sudo nano /etc/sysctl.conf

And add the following line of code at the end in the same system configuration file:

vm.vfs_cache_pressure=50

That’s it. The Swap space is added into your cloud server and also tweaked for best performance settings.

Installing the required PHP modules

Flarum required a few additional modules to be installed along with the commons. To proceed with installing all the required files at once, run the below command lines in SSH.

sudo apt-get install php7.3-mbstring php7.3-gd php7.3-json php7.3-xml php7.3-zip php7.3-curl openssl
sudo phpenmod pdo_mysql

This will completely install all the necessary modules for the Flarum to run on PHP Processor.

Creating a new database table in MySQL

Flarum needs the database to store and retrieve all the information stored in the forum. It supports both MySQL and MariaDB.

We can even use the same database that we created for WordPress in MySQL, but that would be less secure. Hence we should always create a fresh database to hold any data for a new program.

Just like WordPress, the Flarum needs 3 database details while installation:

  1. Database name: flrmdatabase
  2. Database user: flrmuser
  3. Database password: flrmpassword

We will be creating a new database and username along with the password for Flarum using these dummy values. Login cloud via an SSH client and run following commands to generate the MySQL DB to install Flarum Forum:

Login into MySQL from SSH using root account:

mysql -u root -p

Enter the MySQL root account password when prompted.
Login into MySQL 8.0 on Ubuntu Cloud Server

Let’s create a database for Flarum. I’ll be using dummy values as mentioned above, however, you can modify as per wish.

CREATE DATABASE flrmdatabase;

Next, we are going to create a MySQL user with password and grant permissions to the database to operate and manage independently.

CREATE USER 'flrmuser'@'localhost' IDENTIFIED BY 'flrmpassword';
GRANT ALL ON flrmdatabase.* TO 'flrmuser'@'localhost';

Now we have created a database and also granted a user with full permission. Commit the changes into MySQL server and exit using the following command:

FLUSH PRIVILEGES;
exit;

Created Database and User for WordPress on MySQL

The MySQL session will be terminated, and you will be back into the Ubuntu shell. We will be using these new database records while installing the Flarum in the browser.

Installing Composer for Flarum

If you’re not aware of this but, Flarum needs Composer to run the installation and support. The composer is a kind of dependency management tool for PHP dependencies which can only be executed by the command line terminal. Thankfully, DigitalOcean provides complete root access along with SSH command.

Below command line will download and install the composer program in your cloud server:

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

Install Flarum Forum Software

Next, we will create the subdirectory folder structure as mentioned above for Flarum installation.

sudo mkdir /var/www/demo/forum
cd /var/www/demo/forum

The previous command cd ... will change our directory selection to the Flarum subfolder. Now install Flarum to create a project inside the subdirectory folder using below command.

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

Install Flarum on LEMP using Composer

This will download the latest available flarum project files and automatically complete the installation. This may take a few minutes to process installation.

Set up and Configure Flarum for sub-directory

Next, grant read & write access to the Flarum folder and also change the ownership.

sudo chown www-data:www-data -R /var/www/demo/forum/
sudo chmod 0775 -R /var/www/demo/forum/

With the recent changes in the program, the Flarum has been installing the files from /public/ folder within our subdirectory structure. Using FTP client like FileZilla, move index.php and assets folder available in public folder to /forum/ subdirectory folder.

You can also move the files using the below command line and ignore the .htaccess file. We are using the Nginx server which does not support it .htaccess.

sudo mv /var/www/demo/forum/public/* /var/www/demo/forum/

Next, you need to edit the flarum and index.php file to make sure the public directory pointer is changed to flarum base folder.

Lookup for similar lines to make the changes such that it will reflect as below, and do not edit any other lines.

require 'vendor/autoload.php';
'base' => __DIR__,
'public' => __DIR__,
'storage' => __DIR__.'/storage',

modified Flarum file in installation

Save both the files after editing.

Configuring the Nginx to support Flarum

Next comes the most important part of configuring the Nginx file. If you miss configuring Nginx, the Flarum will always encounter with error 500 alert and never load.

Open the Nginx configuration file which is used for WordPress. The configuration file is generally located inside this path, can be accessed using FTP:

/etc/nginx/sites-available/

My nginx configuration file name is default, I’ll open add the below line of code within server { ... } block below WordPress location { ... } directive block.

Alert: Please consider having a backup before modifying the .conf file. If anything goes wrong web server, the website will down. 

server { ...
... existing lines...
WordPress location / {} lines
...
// This rule help to read the index.php file in Flarum root folder
     location /forum/ {   
        root /var/www/demo;
        try_files $uri $uri/ /forum/index.php?$query_string;
     }
// This rule help to access the sitemap.xml file without any errors
     location = /forum/sitemap.xml {
        try_files $uri $uri/ /forum/index.php?$query_string;
     }
...
... existing lines ...
}

Save the configuration file, and test for any Nginx error.

nginx -t

If the test runs successfully OK, then restart the Nginx to commit the changes.

sudo service nginx restart

After installation, try to access the flarum forum at the subdirectory to complete the installation process. Since I’ve installed the forum under the demo site. I will be able to complete the installation:

https://demo.restorebin.com/forum/

Install Flarum community forum
On the installation page, just enter the details of your MySQL server database tables that we created. Set up the admin login credentials and password.

For demo purposes, I will be using my existing WordPress database name, username, and password that I created while installing WordPress on the LEMP stack. Even you can use your WordPress database details, however, I strongly recommend to create a separate MySQL database of live Flarum installation.

Once all the fields are filled, just hit on [Install Flarum] to complete the installation. It will take a moment to complete the entire installation. You will be redirected to the Flarum Forum home page after completion.
restoreBin Demo Flarum InstallationHit on the Log In link and enter the Admin credentials that you’ve set on the installation page. If everything goes well, you will be able to access the admin dashboard and proceed with further setup.
Flarum Administrator Page for new installation

Troubleshooting Flarum Install issue

If you’re facing any issue with the installation and/or login into Flarum forum, then you should typically consider checking these 3 files in the installation folder:

  • flarum — helps in run the Flarum installation
  • index.php — used as Flarum home page file
  • config.php — it’s Flarum’s configuration file

The config.php file should the most important file which helps to execute and run the Flarum software. Here is the config.php file snippet for my dummy installation:

<?php return array (
  'debug' => false,
  'database' =>
  array (
    'driver' => 'mysql',
    'host' => 'localhost',
    'database' => 'flrmdatabase',
    'username' => 'flrmuser',
    'password' => 'flrmpassword',
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => 'flrm_', << this is optional unless you've set while installation.
    'port' => '3306',
    'strict' => false,
  ),
  'url' => 'https://demo.restorebin.com/forum',
  'paths' =>
  array (
    'api' => 'api',
    'admin' => 'admin',
  ),
);

Let me know in the below comments if you’ve any problem with the Flarum installation along with WordPress.

Watch the Flarum Installation Tutorial

Watch this video tutorial to install Flarum software on the Ubuntu LEMP Stack server along with WordPress Blog in the root folder. The Flarum is installed in sub-directory.

I hope this help, please subscribe to our channel for more video.

What’s next after Flarum installation?

We have now completed the installation and also logged into our administrator dashboard. Next, we will see how to install flarum extension to enhances the features within Flarum.

The extensions are similar to WordPress plugin that adds the abilities which are not readily available in Flarum installation. We are going to cover some of the most important and frequently used Flarum extensions to power-up our forum software.

If you've any thoughts on Quickly Install Flarum Community on LEMP Stack along with WordPress, then feel free to drop in below comment box. Cheers!

Share
Kushal Azza
Kushal Azza
Fond of latest technologies and gadgets. I'm a digital dev and analytics consultant. Also, the geek behind this blog!

2 Responses

  1. Yuka says:

    What about a post about installing Flarum on a Mac (locally and on a shared server)?

    • Kushal Azza says:

      Hi Yuka, I have added the topic in my bucket list. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *