Moving Domains with WordPress and phpMyAdmin

16. Apr, 2010

Moving your WordPress site from one domain to another can be a tricky affair if you aren’t overly familiar with MySQL and database handling. Here, I’ll go through a simple way to make it happen, by exporting and editing your MySQL data using phpmyadmin and a text editor.

phpMyAdmin is usually provided by most hosting companies and acts as a nice and easy way to access your MySQL data without having to actually code any, or get your hands dirty.

Step One: Export Your Existing Database

export database

To get your database exported from your existing server or localhost and into a specific file on your computer, you must first log in to your phpMyAdmin area and select the export tab on your database. There’s a heap of options there, but don’t be daunted, as the defaults will be fine. Make sure, however, you check “Save as file”. This will save a file onto your computer containing every single bit of data from your WordPress database. Now you can make the necessary changes to the file.

Step Two: Find/Replace All Occurrences of the Old Domain Name

Open up the .sql file in any text editor. For this you can use Dreamweaver, Notepad, TextMate, Text Edit or anything at your disposal. The only thing to be wary of is that the file size on large sites will be large, heavy and cumbersome on some computers, because of the sheer amount of text involved. If your computer starts wheezing, try and bare with it!

Using the find/replace feature on your text editor, type in your old domain name, and in the ‘replace’ section, put in your new domain name. It might take a little time to complete, depending on your computer, and it normally replaces a few hundred occurrences of your old domain name.

Step Three: Find/Replace All Occurrences of the Absolute Path

Next up is to change the Absolute Path of your WordPress site. This can be a bit baffling,  especially if you have no idea what an Absolute Path is. Just to clarify, your website’s Absolute Path is the place where all of its files live on the server it uses, and it tends to be needed by WordPress for the media gallery uploader and plugins that involve uploading files.

The easiest way to find out your absolute path is to create a php file and write:

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

When you view this output in a browser, you will find the absolute path, which normally looks something like “/var/www/my-domain”.

Now that you have this new information, replace your current absolute path with your new absolute path in your .sql file. There should only be a few instances of this.

Step Four: Importing the Adjusted Database

Now that we’ve made the necessary changes you can save your .sql file and head to the phpmyadmin control panel on your new domain. Here, make sure you are working with an empty database, or add a new database, and then head to ‘import‘. Pick the edited .sql file from your computer, and let it upload.

Step Five: The End

With the database set up and ready to rock, we can upload all of the files to the new domain, except for config.php. This is the file that tells WordPress how to connect to the database, and as we’ve changed servers the database details will not be correct.

Once everything is uploaded you can head to your-new-domain.com and, thanks to the lack of a config.php file, you will be greeted with a WordPress installation screen:

There apears to be no config file

Now you can follow the lovely WordPress instructions to put in your new database details, and a new config file will be created on your server.

Categories: Wordpress

Leave a Reply