In 2014, I migrated the OpenPetra forum from phpBB to Discourse. The reason was that Discourse had a fresh look on the way how forums can be done, it had a nice design, and easy and modern user interface. Here is the post about the details:

Unfortunately, the requirements of Discourse for RAM is quite high, and you cannot just install it inside a shared hosting environment, because it is recommended to be run inside a docker container. It uses technology that I just don’t know very much, with Ruby on Rails and Redis etc.

Then I discovered Flarum, which is written in PHP, but looks as nice and feels as modern as Discourse. It does not have exotic requirements, it just works. It is helpful to have an SSH account, to install the dependencies with composer, but that is available at Hostsharing for my shared hosting anyway.
Flarum is still work in progress, and officially in Beta testing. But you can run your forums in production with the latest Beta already, if you know what you are doing.

So now the issue is, how to migrate your forum from Discourse to Flarum.

At, we worked on a migration tool, based on the scripts, and

We did not cover all aspects, but only those issues we needed for our OpenPetra forum.

Things we covered were:

  • Format text properly, code, lists, http links, etc.
  • convert categories to tags
  • keep the users email addresses

We did not cover:

  • migration of uploaded content
  • we did not convert the user passwords (each user must use the resend password functionality of Flarum)
  • and probably more…

So this blog post has the goal to make our script public, and to encourage you to use it and improve it! Pull Requests are welcome, or just fork it and use it as you like!

We started to host the script first at, then at, and now the official home for the script is:

Of course, in your real life scenario, you will have a database already. But for contributing to this script, we might need a test database, for reproducing specific situations. See my other post for details how to create a test database with dummy data for Discourse!

Setting up Flarum is quite easy if you can access your webspace with SSH and you can run Composer. See the german instructions how to install Flarum inside your Hostsharing account.

If you are working with a virtual machine and CentOS7, this Ansible script might be useful:

You can run the playbook like this (assuming your test server or container has the IP, and you can access it as root via SSH and via HTTP):

ansible-playbook flarum.yml -u root -e working_host=

For running the script discourse_to_flarum.php, you also need a PostgreSQL database inside that container. This Ansible playbook will setup PostgreSQL, and will load the Discourse Backup into the PostgreSQL database. It will also install pgadmin and phpMyAdmin, which helps with debugging of the conversion routines.
You can run the playbook like this:

ansible-playbook migration.yml -u root -e working_host=

After this, you can access phpMyAdmin on the url, the user is flarum and the password is flarum. You can access phpPgAdmin on the url, the user is discourse, and the password is discourse.
And on, your Flarum forum is running.

Now you can actually run the conversion script:

cd /root/flarummigration
composer update
cp migrate-example.yaml migrate.yaml
# perhaps you need to modify the database credentials in migrate.yaml if you have your own setup
# if your prefix is not fl_ for the flarum tables
sed -i "s/fl_//g" migrate.yaml
php discourse_to_flarum.php

to reset the flarum database for a rerun:

zcat ../flarum.sql.gz | mysql -u flarum flarum -p
# vi discourse_flarum.php, or vi migrate.yaml
php discourse_to_flarum.php

Here are two screenshots of the sample posts in Discourse and in Flarum after the migration (mind you, some of the BBCodes also don’t work in Discourse…)




So there is probably still quite some work to do. Pull requests are welcome!

Tags: , , , , ,
Posted in Hosting, Software Development | Comments Closed

This post is part of the work on a project to migrate a forum from Discourse to Flarum. See the related post here: Migrating a forum from Discourse to Flarum

Of course, in your real life scenario, you will have a database already. But for contributing to the script discourse_to_flarum.php, we need a test database, for reproducing specific situations.

It took a while to figure out how to create a test database…

Initial Setup of a test installation

First, follow the instructions at to setup Discourse with a docker container.

On Fedora, I did:

wget -qO- | sh
mkdir /var/discourse
git clone /var/discourse
cd /var/discourse

I changed the hostname from to localhost, and used as the E-mail address for the admin account. For the SMTP settings, you must enter values different than the defaults, but I use dummy values and create the admin account as described below.

My values for discourse-setup for a local test installation of Discourse:

Hostname for your Discourse? []: localhost
Email address for admin account(s)? [,]:
SMTP server address? []:
SMTP port? [587]: 
SMTP user name? []:
SMTP password? [pa$$word]: mypassword
Optional email address for setting up Let's Encrypt? (ENTER to skip) []:

To activate the admin user, type these commands:

cd /var/discourse
./launcher enter app
rake admin:create

I use the Email address for admin account specified above, eg., and I am using the password Demo1234Demo1234! for this test database.

root@localhost-app:/var/www/discourse# rake admin:create
Repeat password:  
Ensuring account is active!
Account created successfully with username example
Do you want to grant Admin privileges to this account? (Y/n)  y
Your account now has Admin privileges!

Now the Discourse instance is running at http://localhost on my Fedora machine, and I can login with user and the password Demo1234Demo1234! (including the exclamation mark).

Just a note, how to start a fresh database again:

launcher stop app
launcher destroy app
rm -Rf shared/standalone/*

Then start again with ./discourse-setup as described above!

Creating sample data

To create some sample data, you can use the script

I have modified that script a little bit, you can see my changes at

To execute this script:

./launcher enter app
cd /var/www/discourse
vi script/profile_db_generator.rb
# make some modifications as described in the gist linked above:
#     unless Rails.env == "profile"  becomes: unless Rails.env == "production"
#      if User.count > 2 becomes if User.count > 3
#      users =    becomes: users =
#      topic_ids = do becomes:  topic_ids = do
#   and for replies: 2000.times do becomes:   200.times do
RAILS_ENV=production sudo -H -E -u discourse bundle exec ruby script/profile_db_generator.rb

This is the output:

root@localhost-app:/var/www/discourse# RAILS_ENV=production sudo -H -E -u discourse bundle exec ruby script/profile_db_generator.rb
installing gabbler gem
Successfully installed gabbler-0.1.0
1 gem installed
Creating 100 users
Creating 10 categories
Creating 100 topics
creating 200 replies

Creating a backup

To create a backup of the Postgresql Database:

./launcher enter app
sudo -u discourse pg_dump discourse | gzip > /shared/postgres_backup/discourse_pg`date '+%Y-%m-%d_%H-%M-%S'`.sql.gz

You find the result on your host machine, in directory /var/discourse/shared/standalone/postgres_backup.

I have uploaded this backup of the PostgreSQL database into the discourse_to_flarum repository.

Tags: ,
Posted in Hosting | Comments Closed

Previously, I have used the discourse packages from because that was easy to install and to maintain, just with Ubuntu packages.

Unfortunately, those packages have not been updated for a while.

Another thing is that I can now run docker within an lxc container, which makes it easier for me to deploy docker on my root server.

So I decided to upgrade my pkgr discourse installation from 1.5.1 to the latest stable docker discourse installation.

These threads and pages have helped me:

So I created a backup of the 1.5.1 installation, within the admin dashboard, and downloaded that locally.

I created an LXC container with Fedora 24 (see

Inside the container:

dnf install docker git which
systemctl enable docker
systemctl start docker
mkdir /var/discourse
git clone /var/discourse
cd /var/discourse
# comment last line, because we want to edit the file containers/app.yml before installing
sed -i 's~./launcher bootstrap~#./launcher bootstrap~g' discourse-setup
# edit containers/app.yml:
#   comment the line with 443:443 because I am using nginx outside of the LXC container for https
#   in section params, add this line:
#     version: v1.5.1
#   I changed UNICORN-WORKERS from 6 to 2, because my forum does not have much traffic
./launcher bootstrap app && ./launcher start app

Now I login to the new discourse installation, with the admin email address specified in discourse-setup. Checking in the dashboard, I have version 1.5.1 indeed.

I restore the backup that I downloaded from the old server (need to make sure to enable restore first in the dashboard settings!).

Verify that the forum works.

Now upgrade Discourse to the latest stable version:

cd /var/discourse
git pull
sed -i "s/^  version:.*/  version: stable/g" containers/app.yml
./launcher rebuild app
Tags: ,
Posted in Hosting | Comments Closed

So it seems that is the new way that forums should work.

Discourse uses Ruby on Rails, Redis and Postgresql on the server side. This means it is quite different than the LAMP stack that you might be used to.

For that reason, the recommended type of installation is via Docker to hide the complexity from the administrator:

I have tried that, but I must say that docker is intended for different kind of applications, if I understand correctly: for deployment of many applications in the cloud, and the data is stored not inside the Docker container but somewhere else.

I personally think that LXC containers are much more suitable for this kind of task. One aspect is that the container feels like a virtual machine, and I can control the IP address of the container using my lxc scripts:

But installing all the requirements of Discourse manually is not an option either. Then I found the Debian and Ubuntu packages provided by

So I followed the instructions at to install Discourse on my Ubuntu 14.04 trusty container.

I use nginx in the host machine to manage SSL for me. I only need to set in the file /opt/discourse/config/site_settings.yml:

use_https: true

My nginx file looks like this:

Now we get to the point where I want to migrate the existing phpBB forum to Discourse:

See this thread about the phpBB importer:

I need to install mysql inside the container, and import the sql data:

apt-get install mysql-server mysql-client libmysqlclient-dev make
/etc/init.d/mysql start
  create database phpbb; 
mysql phpbb < backup-db-phpbb.sql

Before I actually import the phpBB data, I disable sending of all emails in Discourse, in Settings/EMail, disable sending of all emails.

Now I need to load the environment variables, so that I use the correct version of Ruby and gems etc.
I have got those commands from the script /usr/bin/discourse:

. /etc/default/discourse
for file in /etc/discourse/conf.d/*; do   if [ -f $file ]; then . $file; fi; done
for file in /opt/discourse/.profile.d/*.sh; do   if [ -f $file ]; then HOME=/opt/discourse . $file; fi; done
# install mysql2 gem
gem install mysql2
#now the import call:
cd /opt/discourse/script/import_scripts
# PATH is not actually passed? therefore specifying path for ruby
RAILS_ENV=production sudo -E -u discourse /opt/discourse/bin/ruby phpbb3.rb

Update November 11th 2014:
I learnt now that you can use this command that will run the upgrade script in the right environment (Thank you Cyril Rohr from!):

discourse run gem install mysql2
discourse run ruby ./script/import_scripts/phpbb3.rb

To deactivate all users that never have posted to the forum, you can do this in Postgresql:

su - postgres
 psql discourse 
   update users set active=false where last_posted_at is null;

Now you can enable sending of emails again.

You could actually create a backup of Discourse, reinstall the container, to get rid of the Mysql database, and import the backup.

Update November 11th 2014:
To upgrade the installation to a newer version of Discourse, you need to run as root:

apt-get update && apt-get upgrade
discourse run rake db:migrate
Tags: ,
Posted in Software Development | Comments Closed