Quickly install Flarum community on Nginx along with WordPress

You can easily install Flarum forum program in subdirectory on Nginx server along with WordPress running in root folder. Just need to adjust the Nginx config with 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 Tech, Digital, Money, Living, and more.

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

I struggled a lot while installing 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!

restoreBin Explore running on flarum forum

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

  • ~/ root folder
    • ~/var/www/html/ WordPress installation
      • ~/var/www/html/flarum/ Flarum installation

Also as I mentioned earlier, both WordPress and Flarum share the nginx.conf file which makes the configuration lot easier.

Install Flarum on subdirectory folder

Let’s get started with the installation process, I’m assuming you already have a LEMP server configured with MySQL database. Since WordPress uses MySQL database, as we are going to use the same database table to install Flarum.

Here is the system requirement for Flarum to run smoothly:

  • Linux OS – personally prefer Ubuntu
  • Nginx server
  • 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
  • FTP access with FileZilla or similar FTP client installed

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 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 system:

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

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

sudo mkdir /var/www/html/flarum
cd /var/www/html/flarum

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

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

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

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

sudo chown www-data:www-data -R /var/www/html/flarum/
sudo chmod 0775 -R /var/www/html/flarum/

With the recent changes, the Flarum has started 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 subdirectory folder.

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

sudo mv -R /var/www/html/flarum/public/* /var/www/html/flarum/

Next, you need to edit the flarum and index.php file to make sure the public directory pointer is changed to flarum base folder. Look up for similar lines to make the changes reflecting below, and do not edit any other lines.

require 'vendor/autoload.php';

'base' => __DIR__,
'public' => __DIR__,
'storage' => __DIR__.'/storage',

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/

Say suppose I have file name Nginx configuration file with the name default.conf, I can open add the below line of code within server { ... } block below WordPress location { ... } block.

Please consider having a backup before modifying the .conf file.

server { ... 
... existing lines...
WordPress location / {} lines
...
     location /flarum/ {    
        root /var/www/html;
        try_files $uri $uri/ /flarum/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 subdirectory to complete the installation process. I’ve install flarum in subdirectory /explore/ hence I can access the flarum on restorebin.com/explore/.

Install Flarum community forum

On the installation page, just enter the details of your MySQL server database and set up the admin login credentials.

You can actually use the WordPress database username and password, however, I strongly recommend to create a separate MySQL database of Flarum installation.

If you've any thoughts on Quickly install Flarum community on Nginx along with WordPress, then feel free to drop in below comment box. Also, please subscribe to our restoreBin YouTube channel for amazing videos tips. Cheers!

Share

Leave a Reply

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