# Migrate a bbPress WordPress plugin forum to Discourse

**URL:** https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876
**Category:** Migrating to Discourse
**Tags:** how-to
**Created:** [August 19, 2016, 2:24pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876 "2016-08-19T14:24:20Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [August 19, 2016, 2:24pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/1 "2016-08-19T14:24:20Z")

</div>

I recently did a bbPress database migration successfully using Discourse’s inbuilt migration script. Now I’m going to share it as a step-by-step tutorial.

**Note:** This tutorial is for the [bbPress plugin](https://wordpress.org/plugins/bbpress/), not the legacy standalone version of bbPress.

### What data can be imported?

- Users (including anonymous users)
- Categories
- Topics
- Posts
- Private Messages (via BuddyPress)
- Attachments
- Permalinks

Before starting the migration set a development environment on your machine (or inside a virtual machine) and run the import there instead of inside the docker container. When I tried it inside docker container I got `peer authentication failed` issue. So I strongly recommending you that you use a development machine. See the [macOS](https://meta.discourse.org/t/install-discourse-on-macos-for-development/15772) or [Ubuntu / Debian](https://meta.discourse.org/t/install-discourse-on-ubuntu-or-debian-for-development/14727) installation guide for development.

Discourse requires Ruby 3.4+. You can check your Ruby version with:

```bash
ruby -v

```

Now we need to install the `libmysqlclient-dev` dependency in order to be able to use the `mysql2` gem.

```bash
sudo apt-get install libmysqlclient-dev

```

After the successful installation go to your Discourse development installation path (typically `~/discourse`).

```bash
cd ~/discourse

```

### Configuring the database connection

The bbPress import script reads all database connection settings from environment variables. You do **not** need to edit the script file. The following environment variables are supported:

| Variable | Default | Description |
| --- | --- | --- |
| `BBPRESS_HOST` | `localhost` | MySQL database host |
| `BBPRESS_USER` | `root` | MySQL username |
| `BBPRESS_PW` | _(empty)_ | MySQL password |
| `BBPRESS_DB` | `bbpress` | MySQL database name |
| `BBPRESS_PREFIX` | `wp_` | WordPress table prefix |
| `BBPRESS_ATTACHMENTS_DIR` | `/path/to/attachments` | Path to bbPress attachments directory |

**If you are migrating your database from localhost** you typically only need to set the database name:

```bash
IMPORT=1 bundle && IMPORT=1 BBPRESS_DB="my_bbpress" bundle exec ruby script/import_scripts/bbpress.rb

```

**If you are migrating your database from an external server** you’ll also need to set the host, username, and password:

```bash
IMPORT=1 bundle && IMPORT=1 BBPRESS_HOST="REMOTE_HOST_NAME" BBPRESS_USER="DB_USERNAME" BBPRESS_PW="MY_SECURE_PASSWORD" BBPRESS_DB="DB_NAME" bundle exec ruby script/import_scripts/bbpress.rb

```

**Congratulations!** Your database successfully migrated from bbPress to Discourse 👏 👋 💥

Now take a backup from admin page `/admin/backups` and import it in your live Discourse website.

* * *

After you moved your bbPress forum to Discourse if you are still going to use your WordPress website as primary site and you’d like to connect it with Discourse then install [Discourse’s official WordPress plugin](https://wordpress.org/plugins/wp-discourse/).

> Last edited by @JammyDodger 2024-05-27T14:54:29Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![kellbot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kellbot/32/121219_2.png) [@kellbot](https://meta.discourse.org/u/kellbot)
#### Post date: [February 14, 2017, 2:16pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/3 "2017-02-14T14:16:27Z")

</div>

Just wanted to thank you for providing this step-by-step guide. We migrated our site from bbpress to Discourse with minimal headache thanks to you. Since we’re running multisite wordpress there were a few tweaks to make to the importer, but other than that it went very smoothly. Thanks!

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [February 14, 2017, 3:43pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/4 "2017-02-14T15:43:26Z")

</div>

If you can share your tweaks then it will be helpful to other multisite owners.

---

<div class="post-metadata">

### Author: ![kellbot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kellbot/32/121219_2.png) [@kellbot](https://meta.discourse.org/u/kellbot)
#### Post date: [February 14, 2017, 3:57pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/5 "2017-02-14T15:57:34Z")

</div>

Admittedly I didn’t take very good notes, and have since killed the VM it  
was on (sorry!) but the basic gist is that if your bbpress install is not  
on the primary site of the Multisite setup you’ll need to a) set the  
environmental variable for BBPRESS\_PREFIX to include your site’s ID number  
(e.g. wp\_6\_ ) and then edit the migration script to use wp\_users rather  
than #{BBPRESS\_PREFIX} for the Users sql. This is because on Multisite  
installations the wp\_users table is shared across sites and then each site  
has its own tables for posts, postmeta, etc.

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [February 14, 2017, 6:27pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/6 "2017-02-14T18:27:46Z")

</div>

thanks for the details 👍

---

<div class="post-metadata">

### Author: ![lead4good](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@lead4good](https://meta.discourse.org/u/lead4good)
#### Post date: [May 25, 2017, 11:26am UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/7 "2017-05-25T11:26:27Z")

</div>

I recently posted on [how to import bbpress into discourse](https://meta.discourse.org/t/how-to-use-the-bbpress-import-script-or-any-other-import-script-with-mysql-dependency/63349)

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [June 5, 2017, 3:21pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/8 "2017-06-05T15:21:34Z")

</div>

Great job on the tutorial! But it’s confusing to have two different guides on this. Do they serve different purposes? Otherwise we should figure out how to merge them.

---

<div class="post-metadata">

### Author: ![lead4good](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@lead4good](https://meta.discourse.org/u/lead4good)
#### Post date: [June 12, 2017, 2:57pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/9 "2017-06-12T14:57:14Z")

</div>

That guide is about how to import bbpress inside of a development environment, mine is how to import bbpress using the docker container. It’s just 2 different ways to go. I’d recommend importing via docker container since it doesn’t ask for the additional step of setting up a development environment, which can be cumbersome.

---

<div class="post-metadata">

### Author: ![lcestou](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lcestou/32/148373_2.png) [@lcestou](https://meta.discourse.org/u/lcestou)
#### Post date: [June 4, 2019, 4:46pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/10 "2019-06-04T16:46:10Z")

</div>

Hello I am stuck trying to import successfully after all **users** are done importing.

As soon it begins to import **anonymous users** it cancels with an error of _“Invalid Email… and Validation failed: Username can’t be blank (ActiveRecord::RecordInvalid)”_.

I added the error below, does anyone encountered this before or have any ideas on what I should do?

Thanks,

```
importing anonymous users...
Invalid email '' for ''. Using '6be92499a6f885cb271d94bffd5e667b@email.invalid'
Error on record: {:id=>"", :email=>"", :name=>"", :website=>nil}
Traceback (most recent call last):
	23: from script/import_scripts/bbpress.rb:512:in `<main>'
	22: from /home/lutechi/discourse/script/import_scripts/base.rb:49:in `perform'
	21: from script/import_scripts/bbpress.rb:31:in `execute'
	20: from script/import_scripts/bbpress.rb:153:in `import_anonymous_users'
	19: from /home/lutechi/discourse/script/import_scripts/base.rb:249:in `create_users'
	18: from /home/lutechi/discourse/script/import_scripts/base.rb:249:in `each'
	17: from /home/lutechi/discourse/script/import_scripts/base.rb:261:in `block in create_users'
	16: from /home/lutechi/discourse/script/import_scripts/base.rb:337:in `create_user'
	15: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:212:in `transaction'
	14: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in `transaction'
	13: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:236:in `within_new_transaction'
	12: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
	11: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:239:in `block in within_new_transaction'
	10: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in `block in transaction'
	 9: from /home/lutechi/discourse/script/import_scripts/base.rb:338:in `block in create_user'
	 8: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/suppressor.rb:48:in `save!'
	 7: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:315:in `save!'
	 6: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:385:in `with_transaction_returning_status'
	 5: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:212:in `transaction'
	 4: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in `transaction'
	 3: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:387:in `block in with_transaction_returning_status'
	 2: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:315:in `block in save!'
	 1: from /home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/validations.rb:52:in `save!'
/home/lutechi/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/validations.rb:80:in `raise_validation_error': Validation failed: Username can't be blank (ActiveRecord::RecordInvalid)

```

---

<div class="post-metadata">

### Author: ![RCheesley](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rcheesley/32/455409_2.png) [@RCheesley](https://meta.discourse.org/u/RCheesley)
#### Post date: [August 13, 2019, 5:09pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/11 "2019-08-13T17:09:49Z")

</div>

Thanks for this useful tutorial - worked for me although I have a couple of small issues:

1. The install process seemed to install postgres 11 and Discourse hosted version support postgres 10, so that’s giving them a bit of a headache!

2. My imported users don’t seem to be able to log into Discourse with their WordPress credentials - I tried it with my own user account, both with the username and the email address, but neither work. I can log into WordPress fine and the user account is present in Discourse, with the associated forum threads. Something changed with passwords/auth maybe?

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [August 13, 2019, 5:46pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/12 "2019-08-13T17:46:53Z")

</div>

Are you using SSO from WordPress?

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [August 13, 2019, 8:42pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/13 "2019-08-13T20:42:56Z")

</div>

> [@RCheesley](#):
>
> My imported users don’t seem to be able to log into Discourse with their WordPress credentials

This requires the [migrate password plugin](https://meta.discourse.org/t/migrated-password-hashes-support/19512). Did you install that?

---

<div class="post-metadata">

### Author: ![RCheesley](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rcheesley/32/455409_2.png) [@RCheesley](https://meta.discourse.org/u/RCheesley)
#### Post date: [August 13, 2019, 9:19pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/14 "2019-08-13T21:19:26Z")

</div>

Hi Michael,

No, that is the first reference I’ve found to the plugin, so thank you for highlighting it - maybe I missed a step somewhere! Thanks for sharing I will take a closer look tomorrow when my eyes aren’t quite so tired!

Ruth

---

<div class="post-metadata">

### Author: ![p0fi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p0fi/32/261315_2.png) [@p0fi](https://meta.discourse.org/u/p0fi)
#### Post date: [September 23, 2019, 2:45pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/15 "2019-09-23T14:45:56Z")

</div>

Hi 👋

Can user uploaded pictures also be migrated?  
The plugin for the user uploads was **GD bbPress Attachments**

Cheers 🍻

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 23, 2019, 4:46pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/16 "2019-09-23T16:46:20Z")

</div>

The script appears to import attachments.

> <https://github.com/discourse/discourse/blob/main/script/import_scripts/bbpress.rb#L280-L283>

You need to set a `BB_PRESS_ATTACHMENTS_DIR` ENV variable with the path to the attachments.

---

<div class="post-metadata">

### Author: ![p0fi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p0fi/32/261315_2.png) [@p0fi](https://meta.discourse.org/u/p0fi)
#### Post date: [September 29, 2019, 12:11pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/17 "2019-09-29T12:11:26Z")

</div>

The uploads of the bbPress plugin appear to be stored in the `/uploads` folder of the WordPress installation. The GD bbPress Attachments was used for this. Im not sure which kind of path I should put in the `BB_PRESS_ATTACHMENTS_DIR` variable. Could you help me here a bit? Should I put the full URL path to the uploads e.g. `http://www.example.com/httpdocs/wp-content/uploads/2018/02/picture.png` or what else?

I saw that the import script didn’t finish successfully since the `import_private_messages` step failed. Private messages were not activated in the forum. I removed that step form the script and it fails with the message: `table wp_bb_attachments doesn't exist` which is true. I can’t find any table for attachments in the database tho. How could that attachments have worked in the first place? 🤔

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 29, 2019, 2:07pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/18 "2019-09-29T14:07:59Z")

</div>

The attachments need to be in a directory on the server where you run the import.

If you don’t see the attachment table that the script is looking for It may be that you have used some different means of handling attachments than the script expects. My guess is that they are either in a different table that you haven’t found or that the relative filename is in the posts themselves.

It sounds like you need to another function to import them. If you have a budget I can help. [Redirecting…](https://www.literatecomputing.com/discourse-migration/) has information about imports. You don’t need full service, it seems, so your cost would be less than suggested there.

---

<div class="post-metadata">

### Author: ![p0fi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p0fi/32/261315_2.png) [@p0fi](https://meta.discourse.org/u/p0fi)
#### Post date: [September 30, 2019, 4:03pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/19 "2019-09-30T16:03:55Z")

</div>

> [@pfaffman](#):
>
> The attachments need to be in a directory on the server where you run the import.

Since Discourse always runs in a docker container should this directory be linked into the import container?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 30, 2019, 4:05pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/20 "2019-09-30T16:05:09Z")

</div>

Correct. If you’re running the import from a container then you need to put those images somewhere that the can be seen from the container and use that path.

---

<div class="post-metadata">

### Author: ![p0fi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p0fi/32/261315_2.png) [@p0fi](https://meta.discourse.org/u/p0fi)
#### Post date: [September 30, 2019, 4:12pm UTC](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876/21 "2019-09-30T16:12:07Z")

</div>

One last question. Since you mentioned your import service I checked the site and did some more digging into my database and found where the attachments are stored. One sentence on your page made me worry a bit:

> For example, some forums can attach files to a post without mentioning them in the body of the message, the import script identifies attachments by replacing references to them in the message body; when this happens, those un-linked attachments are omitted.

I found that my attachments where stored in the `wp_postsmeta` table as `_wp_attached_file`. The post itself which had this attachment linked however does not have a mention of this in the post body. It seems the only link here is the `post_id` and its `meta_id`. Does this mean that this is an “un-linked attachment” and will be omitted?

[Next page](https://meta.discourse.org/t/migrate-a-bbpress-wordpress-plugin-forum-to-discourse/48876.md?page=2)
