Vanilla — A BBPress Alternative

I needed a searchable knowledge base, a forum, to use on Tap That Brain website. At first, BBPress looked like a great option. But it turned out to be ineffective with the block based theme I use called Quadrat.

Stack Overflow for Teams was next on my list. However, I didn’t like the fact that my users have to leave my website to find information. So I had to explore further.

I ran into thread, titled “Looking for alternatives“, on BBPress forum. Crazy, isn’t it? However, that thread made me realize how a forum can foster community interactions.

I found Ipstenu’s comment in the thread. Ipstenu is a well known name in the WordPress space. So I was more inclined to explore her list of alternatives. Out of the many options, I chose to go with Vanilla. I like the fact that Vanilla is a open source software.

Things to consider

  1. TapThatBrain.com is powered by WordPress. I have installed WordPress application on the root directory. For the sake of understanding, let us assume that the root directory is /var/www/tapthatbrain.com/
  2. I would like to have a forum at TapThatBrain.com/forum

Installation

Download the Vanilla application from https://open.vanillaforums.com/download. From their documentation, installation appeared to be simple. But it wasn’t the case with me.

Unzip the downloaded file at /var/www/tapthatbrain.com/forum and navigate to TapThatBrain.com/forum on the browser to complete the installation.

Setting up the nginx server block was quite challenging. Vanilla’s documentation has listed the config to be included with nginx. However, I had to tweak it a bit to get it working with my setup.

NGINX configuration

Here’s how I got Vanilla working alongside WordPress. In my case, I know all forum requests are routed through TapThatBrain.com/forum/

NGINX cannot process PHP files. We use FastCGI to handle PHP processing. I shall talk more about this in a minute. But let us see how I handle all /forum/ requests before that.

Handling the /forum/ requests.

location /forum/ {
  try_files $uri $uri/ index.php$is_args$args;
}

The above statement matches all requests made to /forum/ and executes the file. If the file isn’t available, it executes the folder. If the folder isn’t available then it executes index.php and passes any $args received.

The above block worked great at first. However, I needed to handle requests like /forum/categories/, /forum/discussions/, etc.

location /forum/ {
  try_files $uri $uri/ @vanilla;
}

location @vanilla {
  rewrite ^/forum/(.*)$ /forum/index.php?p=$1 last;
}

The goal of the above block is to rewrite the URLs like /forum/categories/ and /forum/discussions/ and rewrite them as TapThatBrain.com/forum/index.php?p=discussions and you get the idea.

We want the rewrite to happen because these URLs are dynamic and are not actual pages. You can read more about the last keyword mentioned in the rewrite directive.

FastCGI PHP processing

In order to process PHP files, we use FastCGI. Pass the fastcgi_pass value and the processing should kick in.

location /forum/ {
  location /forum/index\.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_param SCRIPT_NAME /forum/index.php;
    fastcgi_param SCRIPT_FILENAME $realpath_root/index.php;
    fastcgi_param X_REWRITE 1;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  }

  try_files $uri $uri/ @vanilla;
}

location @vanilla {
  rewrite ^/forum/(.*)$ /forum/index.php?p=$1 last;
}

A nested location block is added for the FastCGI processing. The nested location block looks for the /forum/index.php. Now I have to re-route all requests via index.php file.

I would soon update this post about re-routing requests via index.php

With this current setup, I will be able to let Tap That Brain users access a forum without leaving the website.

If you’re curious, checkout the forum at https://www.tapthatbrain.com/forum/

Leave a Reply

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