Migrate a XenForo forum to Discourse

Hey guys so after trying for a week or so I decided to import the database on docker app which I hoped it will succeed without any issues. TBH I got some issues at first but it turned to be all easy to solve.

Now I would recommend doing this only once before you deploy your production site, after importing everything take a Discourse backup, wipe everything out and install new Discourse instance then restore the imported db.

Ok let’s begin:

  1. First lets backup your old database from your old server, sign in to your Discourse server then:

     ssh USER@XENFORO_SERVER_IP  # Use -p argument to specify custom port
     mysqldump -u XENFORO_DATABASE_USER -p XENFORO_DATABASE_NAME > xen_db.sql
     exit
    
  2. After installing Discourse start the app:

     ./launcher start app
    
  3. Now lets pull the database backup from xenforo server:

     scp USER@XENFORO_SERVER_IP:~/xen_db.sql /var/discourse/shared/standalone/xen_db.sql
    

    If you changed the ssh port use -P argument

     scp -P 2222 USER@XENFORO_SERVER_IP:~/xen_db.sql /var/discourse/shared/standalone/xen_db.sql 
    
  4. Login to docker machine, install and start mysql:

     docker exec -it app bash
     sudo apt-get update
     sudo apt-get upgrade
    

    During the installation you will be asked to set a root password for mysql

     sudo apt-get install mysql-server mysql-client libmysqlclient-dev
     service mysql start
    
  5. Login to mysql and create new database:

     mysql -u root -p
    

    Enter your mysql root password then

     create database xenforo_db;
     exit;
    
  6. Import your xenforo database into the new one:

     mysql -u root -p xenforo_db < /shared/xen_db.sql
     # Enter your mysql root password and wait until it finish
    
  7. Include the gem in discourse Gemfile:

     echo "gem 'mysql2'" >>Gemfile
    
  8. Run bundle install:

     bundle install --no-deployment
    
  9. Edit the importer script and change the following:

    vi /var/www/discourse/script/import_scripts/xenforo.rb
    XENFORO_DB = "xenforo_db"
    @client = Mysql2::Client.new(
      host: "localhost",
      username: "root",
      password: "Your mysql root password",
      database: XENFORO_DB
    )
    
  10. You are set to go now, run the importer:

    RAILS_ENV=production bundle exec ruby script/import_scripts/xenforo.rb

  11. If you get the error 'Peer authentication failed for user "discourse"':

  12. Edit the file /etc/postgresql/9.5/main/pg_hba.conf

  13. change all ‘peer’ to ‘trust’ and save the file

  14. restart postgres server: service postgresql restart

Run the importer again and this time it should work without any problem, be patient this might take a while based on your database size.

Hope this helps someone. :slight_smile:

19 Likes