Saturday, April 24, 2010

Moving wordpress to a new host and to a new domain name tips

Finally worked this out, and was able to move entire wordpress with all posts and settings intact from one host and domain name to a new host and new domain name. It's the first time I've really used phpmyadmin for exported/imported databases aswell.

I wanted to practice moving the whole thing over, so I know what's involved for next time if theres a big mission critical site. Previously I had been just doing fresh install to move sites from testing to live, adding theme / plugins and settings manually, as there usually aren't posts etc for new sites, its still fiddly going into each admin setting page for everything page by page.

Basically I followed the process described here 'Moving wordpress to a new server'

Here's things that tripped me up:

1/ Old server .htaccess: With the downloaded entire wordpress install folder, I also downloaded the old servers .htaccess file and uploaded this to the new server, which caused some funny error where the browser wanted to download the .php file of the page - very dodgy. The .htaccess file was obviously for the specific server that it came from, so it had to be deleted.

2/WP config file/new database setup: Then I got an error when trying to visit the site. Something like 'can't contact database'. In the wp-config.php file, I had used the wrong db user name. On the new server i created a new database, and imported everything using phpmyadmin, but the new server automatically adds a prefix to that username I made, which i didn't realise, so adding the prefix in the config file made it work. I simply hadn't looked in the hosts sql manager to look at the databases listed and their users, and how they were written.
(Also used fantastico on the new server to install wordpress as a test, just incase the server was bungling wordpress, rather than my settings. When it worked via the fantastico install, I downloaded the wp-config.php file and look at the settings it used. This also gave me a hint about the prefixes the server was adding, but mainly I wanted to check that HOSTNAME variable was set right aswell, I had guessed localhost, but some hosts have a special setting.)

3/Permalinks: All my plugins and everything seemed to be there, just as it was, but when i tried to navigate around the site, i get 'not found', because permalinks is screwed. Go to settings > permalinks and you see a helpful little note that your .htaccess file isn't writable. (actually it dosn't exist because as I said I deleted it before). So I make a new one and upload the code from that message and presto, its all working. Also, I see that the offending line then in the old .htaccess file I deleted must have then been "AddHandler php5-script .php"
Its still saying its not writable, so maybe later, look at the correct permisions to set on it, and the other files. http://codex.wordpress.org/Changing_File_Permissions

4/ File download time: The process of downloading all the WP core files twice and uploading took about 4 hours and made the internet slow. I should have done some zipping thing, so the files are zipped before downloading, I'll look up how to do that next time.

Another way to do it, is just to export the wordpress posts etc using the export / import feature in wordpress install. But this dosn't keep ALL settings, so it may or may not be faster/easier (so you do new install on new server etc) http://wordpress.org/support/topic/284535
Depends really. Personally, I just export the XML from dev environment and import to WP install in client's server. Upload customized theme along with a couple or so plugins in new server. Arrange settings and options for plugins as needed and you're done in 30 minutes or so.
In some cases, database export and import is required and I follow these instructions

Further stuff to do when moving domain names:
Also, if the site your moving was a live site , with lost of backlinks to it from out there on the web, you'll loose all those referers unless on your old server you... (from: http://www.wptavern.com/two-wordpress-migration-tips )
Redirect Old domain to New domain (htaccess redirect)
Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymLinks

RewriteEngine on

RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
.