# phpBB 3 Importer (old)

**URL:** https://meta.discourse.org/t/phpbb-3-importer-old/17397
**Category:** Feature
**Created:** [July 9, 2014, 6:57pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397 "2014-07-09T18:57:02Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [July 9, 2014, 6:57pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/1 "2014-07-09T18:57:02Z")

</div>

**NOTE** : _This guide is out-dated. [Follow this guide instead!](https://meta.discourse.org/t/importing-from-phpbb3/30810)_

* * *

I committed [a script to import from a phpBB 3 to Discourse](https://github.com/discourse/discourse/blob/master/script/import_scripts/phpbb3.rb), similar to our [Drupal](https://github.com/discourse/discourse/blob/master/script/import_scripts/drupal.rb), [Kunena](https://github.com/discourse/discourse/blob/master/script/import_scripts/kunena.rb), and [bbPress](https://github.com/discourse/discourse/blob/master/script/import_scripts/bbpress.rb) importers. Contributions and fixes are welcome!

Thanks to [ruby-bbcode](https://github.com/veger/ruby-bbcode) and @haiku’s [ruby-bbcode-to-md](https://github.com/inflatablefriends/ruby-bbcode-to-md), some bbcode can optionally be converted to markdown before importing into Discourse. I made a fork that does some conversion that is specific for Discourse. The script will also handle some other phpbb-specific markup, like smileys and links that use `<!-- m -->`, etc.

## Usage:

Edit the bbpress3.rb file to change the MySQL connection info (`PHPBB_DB`, and `Mysql2::Client.new(...)`) so it connects to a local copy of the phpBB database.

To convert phpBB’s bbcode to markdown before importing, install the ruby-bbcode-to-md gem. In a temp directory:

```plaintext
git clone https://github.com/nlalonde/ruby-bbcode-to-md.git
cd ruby-bbcode-to-md
gem build ruby-bbcode-to-md.gemspec
gem install ruby-bbcode-to-md-0.0.13.gem

```

Run the import, from the discourse project directory:

```plaintext
ruby script/import_scripts/phpbb3.rb bbcode-to-md

```

---

<div class="post-metadata">

### Author: ![InsaneMosquito](https://avatars.discourse-cdn.com/v4/letter/i/7cd45c/32.png) [@InsaneMosquito](https://meta.discourse.org/u/InsaneMosquito)
#### Post date: [July 9, 2014, 7:22pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/2 "2014-07-09T19:22:48Z")

</div>

To confirm what I think I’m reading, we need to have a copy of the phpbb database and mysql on the same server we are running Discourse on, correct?

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [July 9, 2014, 7:43pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/3 "2014-07-09T19:43:40Z")

</div>

That’s how I’ve been doing it, but if you can connect to a remote mysql server, then that will work too. Just update the connection info to whatever works in the script.

```plaintext
    @client = Mysql2::Client.new(
      host: "localhost",
      username: "root",
      #password: "password",
      database: PHPBB_DB
    )

```

Connecting to the live production database is probably a bad idea, since data will be changing.

---

<div class="post-metadata">

### Author: ![InsaneMosquito](https://avatars.discourse-cdn.com/v4/letter/i/7cd45c/32.png) [@InsaneMosquito](https://meta.discourse.org/u/InsaneMosquito)
#### Post date: [July 9, 2014, 8:41pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/4 "2014-07-09T20:41:53Z")

</div>

> [@neil](#):
>
> Connecting to the live production database is probably a bad idea, since data will be changing.

If the PHPBB board (gah, to many 'B’s) is closed for maintenance though, that shouldn’t be a problem as very few people with specific privileges would be able to do anything on the board at the time.

---

<div class="post-metadata">

### Author: ![haiku](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/haiku/32/103858_2.png) [@haiku](https://meta.discourse.org/u/haiku)
#### Post date: [July 9, 2014, 10:57pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/5 "2014-07-09T22:57:21Z")

</div>

> [@neil](#):
>
> Thanks to ruby-bbcode and @haiku’s ruby-bbcode-to-md, some bbcode can optionally be converted to markdown before importing into Discourse.

I’m glad you found what I did useful… I believe this is the first time code I wrote has been adopted by an open-source project 😃

---

<div class="post-metadata">

### Author: ![Chili](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chili/32/40331_2.png) [@Chili](https://meta.discourse.org/u/Chili)
#### Post date: [July 9, 2014, 11:12pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/6 "2014-07-09T23:12:03Z")

</div>

Congrats! It really helped me converting our forum over so my personal thanks for all your hard work.

---

<div class="post-metadata">

### Author: ![Frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@Frank](https://meta.discourse.org/u/Frank)
#### Post date: [July 10, 2014, 3:17am UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/7 "2014-07-10T03:17:38Z")

</div>

Neil, as a creator of many import scripts, cleanup scripts and scheduled tasks for processes, I just want to say that there is a special rung in hell for import processes.

![](https://global.discourse-cdn.com/meta/original/3X/1/b/1b18bda951a59ccf6aebb99944087a38beed31fc.jpg)

Seriously though, I give you much respect for doing ‘invisible-to-end-user’ work.

---

<div class="post-metadata">

### Author: ![Wint](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wint/32/107060_2.png) [@Wint](https://meta.discourse.org/u/Wint)
#### Post date: [July 10, 2014, 4:12pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/8 "2014-07-10T16:12:19Z")

</div>

Probably a noobish question but I’ve edited the file and scp’d it to my server, where is the script/import\_scripts folder if you used the docker setup?

Also, does this take care of not spamming users when new posts are created?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [July 10, 2014, 5:10pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/9 "2014-07-10T17:10:39Z")

</div>

Great script. Any chance that it could **import polls** as well?  
Or should I wait and hope that the [official importer](https://meta.discourse.org/t/importing-phpbb-into-discourse/7956/100) will support this?

---

<div class="post-metadata">

### Author: ![haiku](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/haiku/32/103858_2.png) [@haiku](https://meta.discourse.org/u/haiku)
#### Post date: [July 10, 2014, 8:10pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/10 "2014-07-10T20:10:17Z")

</div>

@gerhard This \*is\* the official importer 😛

---

<div class="post-metadata">

### Author: ![MartyKube](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@MartyKube](https://meta.discourse.org/u/MartyKube)
#### Post date: [August 3, 2014, 8:23pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/11 "2014-08-03T20:23:55Z")

</div>

I’m trying out the phpbb3.rb conversion script and am having a little trouble. I suspect it’s a basic ruby thing… I’ve new to ruby.

What I’ve done:

1. install discourse locally with discourse\_docker
2. Signed into discourse and created my admin account. Things look good, basically empty forum.
3. Entered the discourse conatiner
4. Edited phpbb3.rb to set the mysql setting
5. installed mysql-client, libmysql-dev,
6. gems install mysql2

I’m getting an error about missing roles in my DB. Does anyone have a suggestion? I know the stack trace suggest that I create a DB, but I already have one 🙂 The stack trace is below

```
root@ubuntu-app:/var/www/discourse/script/import_scripts# ruby phpbb3.rb 
2014-08-03T19:54:58Z 1990 TID-otwl8st54 INFO: Sidekiq client with redis options {:url=>"redis://localhost:6379/0", :namespace=>"sidekiq"}
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect': FATAL: role "root" does not exist (ActiveRecord::NoDatabaseError)
Run `$ bin/rake db:create db:migrate` to create your database
	from /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
	from /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-
...
	from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /var/www/discourse/script/import_scripts/base.rb:19:in `initialize'
	from phpbb3.rb:14:in `initialize'
	from phpbb3.rb:295:in `new'
	from phpbb3.rb:295:in `<main>'

```

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [August 3, 2014, 8:28pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/12 "2014-08-03T20:28:15Z")

</div>

Try running it with sudo:  
`sudo -E -u discourse ruby phpbb3.rb`

---

<div class="post-metadata">

### Author: ![MartyKube](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@MartyKube](https://meta.discourse.org/u/MartyKube)
#### Post date: [August 3, 2014, 9:51pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/13 "2014-08-03T21:51:11Z")

</div>

@gerhard Thank you for the advice.

I got a different error, same stack. Below is the top of the stack. Seem like it’s looking for a discourse\_development db?

```
root@ubuntu-app:/var/www/discourse/script/import_scripts# sudo -E -u discourse ruby phpbb3.rb 
2014-08-03T21:36:25Z 150 TID-oumvhi6j8 INFO: Sidekiq client with redis options {:url=>"redis://localhost:6379/0", :namespace=>"sidekiq"}
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect': FATAL: database "discourse_development" does not exist (ActiveRecord::NoDatabaseError)
Run `$ bin/rake db:create db:migrate` to create your database

```

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [August 3, 2014, 9:56pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/14 "2014-08-03T21:56:07Z")

</div>

You need to set the Rails environment:  
`RAILS_ENV=production sudo -E -u discourse ruby phpbb3.rb`

Also, you can avoid the repetitive `sudo` cruft by becoming the `discourse` user instead of editing and running these scripts as `root`. Just run `su - discourse` after entering the container.

---

<div class="post-metadata">

### Author: ![MartyKube](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@MartyKube](https://meta.discourse.org/u/MartyKube)
#### Post date: [August 3, 2014, 11:51pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/15 "2014-08-03T23:51:33Z")

</div>

@elberet Sweet! Thanks that was it.

Is it work adding some documentation around this for ruby newcomers like me? I could write up a README.md for discourse/script/import\_scripts?

---

<div class="post-metadata">

### Author: ![MartyKube](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@MartyKube](https://meta.discourse.org/u/MartyKube)
#### Post date: [August 4, 2014, 12:34am UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/16 "2014-08-04T00:34:40Z")

</div>

I found one minor issue:

```
creating users
Skipping user id 1 because email is blank
      641 / 1041 ( 61.6%) Skipping user id 68191 because email is blank
     1043 / 1041 (100.2%)    
creating categories
    Admin
    The Kiteboarding
    The Gear
    Everything Else
    Snowboarding/Ski
    Other sports - MTB, Wake, SUP, Surf and anything else
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/validations.rb:57:in `save!': Validation failed: Category Name is too long (maximum is 50 characters) (ActiveRecord::RecordInvalid)

```

I think this can be fixed by changing the mysql select to trim category names to 50 chars. I’ll put that in a pull request.

[https://github.com/discourse/discourse/pull/2618](https://github.com/discourse/discourse/pull/2618)

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [August 11, 2014, 9:15pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/17 "2014-08-11T21:15:25Z")

</div>

I’ve tried running the importer again - this time using `bbcode-to-md` as parameter.  
I built and installed the gem using the instructions in the first post.

Now, when I’m executing `ruby script/import_scripts/phpbb3.rb bbcode-to-md` I get the following error:

```
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.6.5/lib/bundler/runtime.rb:34:in `block in setup': You have already activated i18n 0.6.11, but your Gemfile requires i18n 0.6.9. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

```

I know why it’s happening. When I install the `ruby-bbcode-to-md-0.0.13.gem` it also installs some dependencies which are the reason for this error. Am I doing something wrong during the installation or how can I fix this?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [August 13, 2014, 6:54pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/18 "2014-08-13T18:54:37Z")

</div>

Have you tried running `bundle exec script/import_scripts/phpbb3.rb bbcode-to-md`?

Note that I have not done imports.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [August 15, 2014, 8:01pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/19 "2014-08-15T20:01:42Z")

</div>

`bundle exec script/import_scripts/phpbb3.rb bbcode-to-md` fails with:

> bundler: not executable: script/import\_scripts/phpbb3.rb

I tried using `bundle exec ruby script/import_scripts/phpbb3.rb bbcode-to-md` too which results in the following error:

```
/var/www/discourse/script/import_scripts/base.rb:11:in `require': cannot load such file -- ruby-bbcode-to-md (LoadError)
        from /var/www/discourse/script/import_scripts/base.rb:11:in `<top (required)>'
        from script/import_scripts/phpbb3.rb:1:in `require'
        from script/import_scripts/phpbb3.rb:1:in `<main>'

```

Here are the steps to reproduce this:

- Bootstrap a new Docker image and log in with `./launcher ssh app`
- Install _ruby-bbcode-to-md_ as root:`
cd /tmp
git clone GitHub - nlalonde/ruby-bbcode-to-md: Convert BBCode to Markdown. · GitHub
cd ruby-bbcode-to-md
gem build ruby-bbcode-to-md.gemspec
gem install ruby-bbcode-to-md-0.0.13.gem`
- Install the mysql2 gem as root:`
apt-get update && apt-get install libmysqlclient-dev
gem install mysql2`
- Change the user and execute the importer:`
su - discourse
cd /var/www/discourse
RAILS_ENV=production ruby script/import_scripts/phpbb3.rb bbcode-to-md`

It works without the `bbcode-to-md`, but fails when that parameter is used. Here’s the complete error message with stacktrace:

```
/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.7.0/lib/bundler/runtime.rb:34:in `block in setup': You have already activated i18n 0.6.11, but your Gemfile requires i18n 0.6.9. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
        from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.7.0/lib/bundler/runtime.rb:19:in `setup'
        from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.7.0/lib/bundler.rb:121:in `setup'
        from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.7.0/lib/bundler/setup.rb:7:in `<top (required)>'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
        from /var/www/discourse/config/boot.rb:6:in `<top (required)>'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/www/discourse/config/application.rb:1:in `<top (required)>'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/www/discourse/config/environment.rb:2:in `<top (required)>'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /var/www/discourse/script/import_scripts/base.rb:19:in `initialize'
        from script/import_scripts/phpbb3.rb:14:in `initialize'
        from script/import_scripts/phpbb3.rb:295:in `new'
        from script/import_scripts/phpbb3.rb:295:in `<main>'

```

As I said in my previous post I think it’s because of the _ruby-bbcode-to-md_ gem, which installs a bunch of dependencies:

```
root@docker-app:/tmp/ruby-bbcode-to-md# gem install ruby-bbcode-to-md-0.0.13.gem
Fetching: i18n-0.6.11.gem (100%)
Successfully installed i18n-0.6.11
Fetching: thread_safe-0.3.4.gem (100%)
Successfully installed thread_safe-0.3.4
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: minitest-5.4.0.gem (100%)
Successfully installed minitest-5.4.0
Fetching: activesupport-4.1.4.gem (100%)
Successfully installed activesupport-4.1.4
Successfully installed ruby-bbcode-to-md-0.0.13
6 gems installed

```

I’m no Ruby expert, so I’m not sure how to solve this. This looks like [dependency hell](http://en.wikipedia.org/wiki/Dependency_hell) to me.  
@neil Could you please take a look at this? Thanks.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [August 15, 2014, 8:48pm UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/20 "2014-08-15T20:48:24Z")

</div>

Try this instead:

As discourse user, add to end of /var/www/discourse/Gemfile:

```plaintext
gem 'mysql2'
gem 'ruby-bbcode-to-md', path: '/tmp/ruby-bbcode-to-md'

```

As root:

```plaintext
cd /var/www/discourse
sudo -E -u discourse bundle install --no-deployment --path vendor/bundle

```

As discourse user:

```plaintext
cd /var/www/discourse
RAILS_ENV=production bundle exec ruby script/import_scripts/phpbb3.rb bbcode-to-md

```

[Next page](https://meta.discourse.org/t/phpbb-3-importer-old/17397.md?page=2)
