I watched Chris Coyier's excellent screencast #87 Moving up with MAMP (you certainly should too) on the subject of transferring a WordPress blog from a local server (or other development server) to a production server. Though he covered a lot of ground and set out a process perfect for less advanced users, especially those with no experience of the Terminal there are a few tricks that more advanced users will be able to use to save a lot of time and headaches.
1. Moving files
The only files that you need to upload are those specific to your installation of WordPress which are contained within the wp-content directory (with one notable exception but we will get to that later). The rest of the files can be fetched straight from the WordPress servers eliminating the lengthy period of time it takes even the better FTP clients to upload all the core WordPress files. This is done by connecting to the production server via SSH and issuing the following commands.
wget http://wordpress.org/latest.tar.gz tar xzf latest.tar.gz
You can then go ahead and upload the contents of the wp-content directory via FTP. However one file in particular will be missing - the .htaccess file used by WordPress to create the permalink structure of your site. You may wish to upload this from your WordPress directory but because the filename is prefixed with a . you are unlikely to be able to see it without changing the settings of your FTP client. The easiest thing is simply to ensure that when the site is uploaded you have WordPress rewrite these rules by disabling and then re-enabling permalinks in the WordPress settings panel.
2. References to the development domain in the DB
In the WordPress database multiple references are made in different records and tables to WordPress' location (i.e. the domain it resides on). When installing on a local development machine these settings are of course different from those of your production server and it is these settings which you will find in the database. This can be avoided however by editing your /etc/hosts file on OSX and Linux (or \Windows\system32\drivers\etc\hosts file on Windows) so that locally the production domain points to your development server.
On Linux / Mac open Terminal and type "sudo nano /etc/hosts", enter your password and add the following at the bottom of the file.
127.0.0.1 www.productiondomain.com
On windows just browse to the \Windows\system32\drivers\etc\ folder and open the hosts file with Notepad and add the same line.
This enables you to configure WordPress as if you were using the production domain and your computer will just redirect your requests for www.productiondomain.com to your local server.
If you haven't done this are your database is littered with references to your development domain no need to fear. All you need to do is find and replace the instances of your local development domain within the exported database dump you will be uploading to the production server. This can be done by executing the following command on the database dump file in Terminal.
sed -i.bak 's/localhost/www.productiondomain.com/g' db.sql
What this does is replace all instances of the string "localhost" with the string "www.productiondomain.com" so that all your database records will reference the new domain rather than your local development version. This command only available on OSX and Linux but one could also use the find and replace functionality of your favourite text editor as long as the database wasn't to large.
3. Permalink Problems
The permalink settings for your blog manifest themselves as entries in your .htaccess file which resides in the root of your WordPress installation. However, as you aren't moving the whole WordPress installation this is often forgotten. This causes many links the worked in the development environment to give 404 errors. There are two ways of fixing this. You could FTP/scp the .htaccess file from your development server to your production server, however, there is an easier way. In the WP Admin Panel on the production server go to Permalinks (under settings) and set check the default option (taking note of the original setting). Save your changes (a message saying "Permalink structure updated" will appear) and then re-check the original setting and save changes again. This will cause WordPress to write the appropriate rules in your .htaccess file and all of your links will work again.
Anyhow, I hope you find this useful and that it speeds up the process a little. Let me know what you think in the comments and if there are any particular requests I will expand upon some more of the minutia of moving WordPress from a localhost to live.
