In the past days, I have upgraded my forums to the latest Beta release of Flarum, 0.1.0-beta.9.

I just want to say how glad I am with using Flarum. It does not need much resources, runs fine in shared hosting at Hostsharing, and is continually improved. Even though it is not a stable version yet, the upgrades work alright.

Here is a summary of contributions I am trying to give back to Flarum:

Here are now some links and notes about developing my own extension, Post Notifications:

For the frontend for the admin settings, I need to transpile the code (see Frontend Development: Transpilation). I don’t do that directly on Hostsharing, because I don’t have npm there, and don’t want to use up the webspace. Therefore I have the development environment on my local Ubuntu.

cd flarum-ext-post-notification
cd js
npm install webpack
npm install
npm run build
git add dist
cd ..
rsync -zvhr --exclude node_modules --exclude .git . xyz00-myuser@mydomain.de:doms/testflarum.mydomain.de/htdocs-ssl/vendor/tpokorra/flarum-ext-post-notification

It seems for upgrading the extension across minor versions, I need to run composer require again, since composer update only updates between releases? Or perhaps I was too quick, and the new tag did not arrive at Packagist yet?

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: https://www.pokorra.de/2014/09/migrate-phpbb-forum-to-discourse-using-the-ubuntu-packages-from-packager-io/

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 TBits.net, we worked on a migration tool, based on the scripts https://github.com/robrotheram/phpbb_to_flarumhttps://github.com/viruxe/phpbb_to_flarum, and https://github.com/Reflic/phpbb_to_flarum.

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 https://github.com/Crusader99/discourse_to_flarum, then at https://github.com/The-CJ/discourse-flarum, and now the official home for the script is:

https://github.com/TBits/discourse_to_flarum

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:
https://github.com/TBits/discourse_to_flarum/blob/master/ansible/flarum.yml

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

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

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=192.168.122.52

After this, you can access phpMyAdmin on the url http://192.168.122.52/phpMyAdmin/, the user is flarum and the password is flarum. You can access phpPgAdmin on the url http://192.168.122.52/phpPgAdmin/, the user is discourse, and the password is discourse.
And on http://192.168.122.52/, 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 https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md to setup Discourse with a docker container.

On Fedora, I did:

wget -qO- https://get.docker.com/ | sh
mkdir /var/discourse
git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse
./discourse-setup

I changed the hostname from discourse.example.com to localhost, and used admin@example.com 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? [discourse.example.com]: localhost
Email address for admin account(s)? [me@example.com,you@example.com]: admin@example.com
SMTP server address? [smtp.example.com]: my.smtp.example.com
SMTP port? [587]: 
SMTP user name? [user@example.com]: my.user@example.com
SMTP password? [pa$$word]: mypassword
Optional email address for setting up Let's Encrypt? (ENTER to skip) [me@example.com]:

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. admin@example.com, and I am using the password Demo1234Demo1234! for this test database.

root@localhost-app:/var/www/discourse# rake admin:create
Email:  admin@example.com
Password:  
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 admin@example.com 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 https://github.com/discourse/discourse/blob/master/script/profile_db_generator.rb

I have modified that script a little bit, you can see my changes at https://gist.github.com/tpokorra/b2e34238dea0243572e822f649a35bab/revisions.

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 = 100.times.map    becomes: users = 10.times.map
#      topic_ids = 100.times.map do becomes:  topic_ids = 50.times.map 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