How to Migrate WordPress Anywhere (Change Directories, Change Servers, or Change URLs)
on November 15, 2011
When you are working with WordPress, sooner or later the time will come when you need to move your install to a new location, be that a different directory or an entirely different server (and possibly change the URL as well. This tutorial is meant to complement the official WordPress migration guide and cover some areas that it doesn’t deal with explicitly. It will focus on three scenarios and assumes competence with a FTP client such as Filezilla and a WordPress 3.0+ install:
- Moving a WordPress Install to a New Directory
- Moving a WordPress Install to a New Server (with URL change)
- Moving a WordPress Install to a New Server (no URL change)
1) Moving a WordPress Install to a New Directory
- Backup your site and any files that you will be moving. Don’t forget to backup databases as well.
- If the directory to which you want to move your WordPress install does not already exist, then create it.
- Log into the admin panel of your blog and go to Administration > Settings > General.
- In the field for “WordPress address (URL)” change the address to the new location of your main WordPress core files.
- In the field for “Site address (URL)” change the address to the new location, which should match the “WordPress address (URL)” field.
- Save Settings — Do not try to open/view your blog after doing this step!!!
- Move all your WordPress files to the new location. It is important that you change the URL locations — i.e. “Site address (URL)” and “WordPress address (URL)” — before you move the files.
- If you are using Permalinks, go to Administration > Settings > Permalinks and update your Permalink structure to your .htaccess file, which should be in the same directory as the main index.php file. (Note: this may be unnecessary in newer WordPress versions)
- If uploaded images are missing, then you need to change the path to the images on every post in your SQL database. Check out this tutorial for further info.
- Under Settings > Media, edit the “Store uploads folder” or all your new uploads will continue to go into the old folder location.
- Existing links to uploaded media will refer to the old folder and must be updated with the new URLs.
- If you host with certain ISPs, your permissions may have changed during this process. Look for any files with “0000” permissions and change them back to “0644”.
- If you are using a theme with menus, links to your home page may still have the old directory in them. Go to Appearance > Menus to update them.
If you forgot to change locations correctly or accidentally changed your WordPress site URL, never fear, all is not lost. You can either edit wp-login.php to reset the URLs, edit your SQL database directly, or use terminal access to set up a symlink. Editing wp-login.php is covered below, for further info on the other two techniques, check out the official WordPress migration guide.
1a) Fixing Accidentally Changed URLs with wp-login.php
Open wp-login.php a text editor and find the following line:
require( dirname(__FILE__) . '/wp-load.php' );
And insert the below lines after it.
//FIXME: do comment/remove these hack lines. (once the database is updated) update_option('siteurl', 'http://your.domain.name/the/path' ); update_option('home', 'http://your.domain.name/the/path' );
Visit http://your.domain.name/wp-login and the URLs will be reset. Test your site to make sure that it is working properly.
2) Moving a WordPress Install to a New Server (with URL change)
For this tutorial, we are assuming that you don’t need your old blog / WordPress install to work after the migration because who needs two identical sites; however , in certain instances, it can be useful to have access to your old blog / WordPress install. If you need your old blog / WordPress install to work after the migration, check out the official WordPress migration guide for further instruction.
- Backup your data. Always. Files and SQL databases.
- Download a copy of your WordPress files from your OLD blog to your local machine and edit wp-config.php, i.e. URL and database settings, to the appropriate settings for the new server.
- Go to your OLD blog and go to Administration > Settings > General. Change both URLs to the ones for your new site.
- Once you have made these changes, download a copy of your SQL database, which is now updated for your new site (keeping a copy of the old one as a backup). Upload a copy of the updated database (see Restoring Your Database From Backup) along with your WordPress files to the new server.
- If you encounter any database connection errors, check wp-config.php to make sure that it is configured correctly.
3) Moving a WordPress Install to a New Server (no URL change)
- Backup your data. Always. Files and SQL databases.
- Download a copy of your WordPress files and a copy of the blog’s SQL database.
- Upload the files to your new server and restore your database (see Restoring Your Database From Backup).
- Edit wp-config.php, i.e. URL and database settings, to the appropriate settings for the new server.
- Change your nameservers over (this scenario typically applies in situations where people are switching hosts).
Leave a Reply