← Back to Archives

NQB2 on the move! (Or "How to move a b2evo blog")

system

So you may notice that I've moved NQB2 to a new web host (hint: take a look at the new URL... http://josephhall.org/nqb2/).

You should update your feeds (see the list in the panel at right). It was a pretty clean move, if you notice any funny business, please send me an email.

For all of you b2evo bloggers out there who love a good how-to, I'll outline (in an extended entry below) the steps I took to make the move and do it cleanly.

[More:]

Moving a b2evolution blog from one host to another

  1. First, you'll need a destination hosting provider... I chose Birdhouse Hosting run by Scot Hacker, the sysadmin of UC Berkeley's J-School. After paying the hosting $$$ and having your DNS record propogate... you should have something like my http://josephhall.org/ domain just waiting for data.

  2. Then, you'll want to export your old blog's database tables. I used phpMyAdmin to do this. In phpMyAdmin, select the database that you want to export, then click on the Export tab. You'll want to export the whole database, so select the database in question. You will also want to select "Enclose export in a transaction" which will make importing the database and it's tables a snap. Have it save the export as a file with no compression. You should be prompted to download a .sql file which you should save locally.

  3. After that, you need to import the old database tables into a new database. Through your hosting provider, add a new database for your blog and a new user. Give that user access privileges for the new database. You should then zip or gzip the SQL file from the last step and upload it to the new domain (then uncompress it).

    You'll need to manually edit the SQL file... look for the lines near the beginning that say:

    CREATE DATABASE 'old_db'; USE old_db;

    Where old_db is the name of the old database that you just exported. You'll want to comment out (with two minus signs, --) the first line here (we created the database in the last step) and then change the old_db in the second line to the name of the database you created above:

    -- CREATE DATABASE 'old_db'; USE new_db;

    Now, our SQL file is ready to be run. Type mysql -u username -p at the command line (with username replaced by the user you created for the blog database in the step above). Enter in the password for this user when prompted. You should now be at a mysql command line prompt. To run the SQL file, type:

    source localhost.sql;

    Where localhost.sql is the name of your SQL file. This will take a little while but will copy all the contents of your old database's tables into new tables in the new database.

  4. Then, you need to copy over the blog's web and php pages to the new site. I recommend using rsync for this purpose as it preserves permissions and such. For example, a command such as this should do the trick (run from the root directory (~/public_html/blog) of your old blog's location):

    rsync -avzue ssh --delete ./ username@newdomain.com:public_html/blog/

    This will sync your new site with the old one and copy everything over, including symbolic links and preserving permissions.

  5. Not done yet. You will have to modify various entries in blog/conf/_config.php on the new site (where blog is the directory of your blog on the new domain). Make sure you change the following entries to reflect the new site:

    define( 'DB_USER', 'username' ); define( 'DB_PASSWORD', 'passwd' ); define( 'DB_NAME', 'new_db' ); define( 'DB_HOST', 'localhost' );

    and also change the $baseurl in the same file a few lines down to point to the new URL for your blog.

  6. Your new site should work now (call it up in a browser)... if you get an "Internal Server Error" it's likely because you have something like AcceptPathInfo On in your root .htaccess file. If this is the case, rename the .htaccess file to something like bak.htaccess and ask your hosting provider to enable this feature.

  7. Now we need to redirect users of the old site to the new site. You can look long and hard at the Apache documentation but there's only one thing you need to do... you'll need to have a one-line .htaccess file in the root directory of your old blog. The one line in this file should look like this:

    Redirect permanent /blog http://newdomain.com/blog

    Where blog is the directory of you old (and new) blog. This essentially redirects all requests for anything in your old blog to your new blog.

  8. Backup the old site and database and save somewhere. You should keep a copy of the SQL file that has your old exported database in it as well as a complete copy of your old blog (I'd use rsync to your local machine).

  9. When you've made backups, then delete the old site except the .htaccess file that is doing the redirecting. You can do a rm -rf * in the root directory of your old blog but make sure you don't zap the .htaccess file.

  10. Finally, poke around the new site and look for broken links (Note: anything that points to your old site is effectively "broken" as it will be redirected by Apache. You can also disable the redirect for a bit and see if everything holds up.)