Moving a WordPress site to a new server or domain

 

I’ve been playing around porting one of my wordpress sites to a free host to test the performance. This is pretty much the same exercise as when I move from one server to another and there are a few possible hiccups involved.

I’ll detail the steps I’ve found that work. If you miss stuff out all manner of strange things can happen.

If I move sites to a new server I like to test them out before making the DNS change to point to the new IP address so my first action is to set up a subdomain of the site in the DNS pointing to the new server – e.g. I’d point www2.digitalham.co.uk to the new IP.

Set up the main domain and the subdomain you’ll be using to point to a directory on the new server using Cpanel or whatever other method your hosting company provide for this.

Use MySQL to export the entire WordPress database from the old server.

On the new server set up a new database and user with all privileges on it – take careful note of the dbname dbuser and password.

Import your SQL backup file into the new database.

Use PHPMyAdmin or equivalent tool to modify option_value for option_names siteurl and home to the new domain name in the wp-options table.

Use PHPMyAdmin to run these global modifies on the wp_posts table
UPDATE wp_posts SET guid = REPLACE (guid, 'old domain', 'new domain');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'old domain', 'new domain');

FTP everything for your site from the old server down to a new folder in your PC. Don’t rely on anything already there as it may not be up to date.

Amend wp-config.php to the new database name, user, and password if you were unable to set these up the same as the old site. You may need to amend the DB_HOST name too – your hosting company should tell you what is required for that.

If you have made any domain name references in your .htaccess (typically protecting wp-login.php from brute force attacks from script kiddies) don’t forget to modify or comment out those too

FTP it all up to the new server.

Check out any special permissions over the standard 744/644 on your current server – at the very least you’ll probably need to make the uploads folder under wp-content world writeable 666.

Your site should now work on the new domain name. Once you’ve tested it out reverse the temporary changes and specify the standard site url – e.g. www.digitalham.co.uk then update the DNS to point to your new server. For a while some users will see the site on the old server and others on the new one. It’s possible you may lose the odd user comment if they make it on the old server before the final changeover. You can reduce that by redoing the database export and import – doing so also means you don’t need to reverse the mods to the temporary url.

In the above description I’ve specified the standard “wp_” table prefix. For security reasons it is better to use something different but don’t be tempted to make that change as part of this exercise. At the very least changes will be needed in the wp_user_meta table to specify the new prefix otherwise the annoying “You are not Authorized to View this Page” catchall error will be sure to appear when you try to use the admin panel. In the DigitalHam database it appears elsewhere too – it seems to be associated with a Plugin but I didn’t investigate further.