When developing a new WordPress CMS / Blog website for yourself or a client it’s often typical to install it on a temporary development location. I use a demonstration domain and install new WordPress installs under sub folders for preview by clients. One problem with installing WordPress in this type of setup is having to move it to it’s final location on a new domain name. WordPress stores information about posts, image paths and other resources using absolute URLs, eg: http://www.devdomain.com/wpdev/wp-content/uploads/myimage.jpg.
Once the site is done and you are ready to move it to your clients domain you are faced with the annoying and somewhat time consuming task of updating all URL paths so that the sites resources will load from the new domain and you can safely remove your development site.
This process can be simple with a little find/replace “massaging” of the mysql database file between export and import from the dev server to the new server.
Here’s the process I go through when moving a WordPress Website installation from one server to another when the domain name is changing:
1. Install the “Simple WordPress Backup” plugin by Bannerweb GmbH. - This allows you to quickly dump the WordPress database into a backup archive. This is not absolutely necessary, but it’s a good idea to have this available for backing up the WP database and also allows you to avoid logging into the hosting account to access phpmyadmin, which can be a timely process if you don’t have the login details handy.
2. Backup the database using the WordPress backup plugin and download the file locally.
3. Download all the website files from the development URL using either FTP or shell. I personally like to use shell access and archive the entire folder so I can directly transfer from one server to another which allows you to skip downloading local and uploading to the target server. Instructions for moving a folder from one server to another using shell can be found here.
4. Fire up your favorite text editor --(I use Coda for OS X)-- any editor will do, but be sure it has find / replace and and will preserve the character set of the mysql file. Open the .sql file wordpress database, make sure you decompress it if it’s saved as an archive. Immediately save it as a copy, just in case you goof it up and need to start over.
5. Search for your development domain / wordpress path and replace with the target domain, be sure to observe the use of the trailing / to ensure the paths are correct, eg:
I usually leave off the trailing slash because the wp-config tables that define the website path do not use a trailing slash. This will replace all the URL’s in the database for images, resources, and other paths that refer to the old domain and make sure they correspond to the new location.
Once you’re done, save the file.
6. Import the database on the new server and take note of the database server, username, database name and password.
7. Edit wp-config.php to reflect the access details for the new database server.
8. Upload all WP files to the new server.
9. If all goes well your WordPress installation will now load and will be pulling all resources from the new domain, not your old development server.
10. You may want to browse through the site and look for broken images and other resources that may be missing. I will right click on theme images and background image to ensure they are being loaded from the new domain, just right-click and click view image. Look at the URL and make sure the domain is correct.
11. You may run into issues with your theme paths being incorrect if you did not use the correct wp tags to load the template path. If this is the case, your content will load without theme images and you’ll need to edit the header file and any other files and correct the theme resources URL’s.