So you want to migrate WordPress …
As much as we work with WordPress, migration is an integral part of our workflow. For the beginning WordPress user, migration can be daunting and result in this dreaded error. Over the years, we’ve adopted a few different strategies to avoid unnecessary pain when migrating a WordPress site. Below are 3 different ways to migrate your WordPress site from one domain to another that, with any luck, won’t result in a meltdown:
1. Copy the files via FTP and import the database
One of our preferred hosting providers, SiteGround, has a great series of tutorials on FTP – check it out and use the Terminal in Mac OS X (or git for Windows, or the plain old command line for Linux) to copy your files from the original location to your hosting server. Make sure to get the necessary credentials to access your hosting (and if it’s SFTP, make sure you add your SSH key to the server, either this way or by using your hosting’s control panel – often times cPanel).
Importing the WordPress database can be tricky – I’d recommend experience using the command line. This article goes over a few different strategies and even covers if your hosting provider uses phpMyAdmin. When importing your database, we recommend using WP Migrate DB on the site you are migrating from. WP Migrate DB will let you do a search/replace in your database file, and will export the new file you can import into your new domains database. WordPress uses absolute paths – you’ll have to set all URLs in the new database to your site’s new domain.
Now that the files and database are transferred over, you still need to change the wp-config.php file to reflect any changes to the database name and user on your new hosting. Search for the following lines:
define('DB_NAME', 'wp-test'); /** MySQL database username */ define('DB_USER', 'wp-user'); /** MySQL database password */ define('DB_PASSWORD', 'password');
Replace ‘wp-test’ with the name of your database, ‘wp-user’ with the name of the database user, and ‘password’ with that user’s password. Save and experience the unadulterated joy of a migrated WordPress site.
Duplicator is a great plugin for backing up, copying, and cloning WordPress sites. And best of all, it’s free and available on the WordPress plugin repository. It works by packaging your site and database and then creating an installer that you can use to move the site.
First, log in as an administrator to the WordPress admin dashboard of your current site and install and activate Duplicator. Then navigate to the Duplicator menu and click “Packages”.
Click on “Create New” to begin creating your export package. Name your package (good idea to include a date) and if you know the new URL, go ahead and fill it out at the bottom of the page – otherwise you can leave the Archive and Installer settings as they are and click “Next”.
At this point, Duplicator will start a system scan – more than likely you’ll get several warnings. None will prevent you from proceeding, but the more of them you get, the more likely you’ll have errors when building the package. Check the “warning status” checkbox and click “Build”.
You should see the following for a (hopefully) short while:
Followed by this (if everything goes as it should):
Download your archive and installer and copy both (via FTP or SFTP) to your new hosting location (in the public_html directory). Then navigate to the your-new-domain.com/installer.php in your browser (replace your-new-domain.com with your new domain). You’ll see this:
You can use an existing MySQL database – just provide the name, connecting user and password. If your hosting provider allows it, the installer can create a new database for you. Once you’ve filled out those fields, click “Run Deployment”. You may have to answer questions about your old and new deployment – do that and (eventually) you’ll land on an install report. Review it for errors – if none, you’ll have a migrated WordPress site. Test your site to make sure links and images work and functionality is intact – otherwise, that’s it! Duplicator can be used from a local deployment to a live server, or from live server to live server. We use it all the time and it’s great.
3. Import your content
If all you care about is your page and post content and media files (but not the theme or plugins), WordPress has a great out-of-the-box solution – Import and Export. Log in as an administrator to the WordPress admin dashboard of your current site and select Tools -> Export in the left sidebar.
You’ll have a choice of the type of content you can export – “All content” selects everything. Choose appropriately and click “Download Export File”. An XML file containing your content is in your possession – now head over to your new hosting, install WordPress and select Tools -> Import. You’ll see the following screen:
Click “WordPress” and you’ll be guided to install WordPress Importer – follow the steps and run Importer. You’ll then be prompted to provide an import file:
Choose your export XML file from your old WordPress site and click “Upload file and import”. If you have attachments, you’ll need to sign off on the transfer – other than that, you’re done! Phew.
Migration doesn’t have to make you cry – a lot of great tools are available to make the process smooth. What are your favorite migration tools for WordPress? Let us know in the comments.