WordPress provides a great mechanism for exporting and importing data simply by using Tools > Export or Import. However when used on large datasets, as well as media files that take time to import, you’re bound to run into timeout issues.
Obtaining an XML export from the source
If you’re exporting from another self-hosted WordPress site, you can learn how to obtain your XML export file from the source site here. If you choose specific content (like posts) and there are images in your content, you will not be able to transfer them without also making an export of type “Media”
How to safely import the XML file at the destination
When importing that file on the destination site under Tools > Import, there are three ways to ensure it imports smoothly:
- Learn how to adjust your PHP timeout values temporarily so that you can avoid Gateway Timeout errors, then head to Tools > Import and import the file. Do not forget to set the timeouts back to their original values post-import to avoid performance issues on the site.
- Use the WP All Import plugin – it batches the data import so that timeouts are not likely to be reached (this is what the built in WordPress import function should do but doesn’t).
- Use the wp-cli utility via an SSH connection to avoid front-end timeouts. Server timeouts are only configured through the web server configuration, and so are not present when importing via command line with wp-cli.
Note regarding Option 1: it can be tricky to estimate how long you need to set the timeout for. If you have more than, say, 100-200 media files in WordPress, it’s recommended to use one of the other two options.
Options 1 and 2 are simpler, while Option 3 (wp-cli) is more robust, but more technical knowledge is required to use it. If you’d like to give wp-cli a try, read on!
Using wp-cli to ensure a reliable import
WP-CLI is a command line method of working with WordPress. Rather than importing using the WordPress admin GUI, you do so when logged in via SSH which bypasses nginx, apache, fastcgi, and php timeouts since it doesn’t use anything but straight-up PHP to run.
This following steps are specific to running this on a Plesk server. It is an advanced guide because you must be familiar with connecting to your server via SSH and using the command line to use it.
- Learn how to install and use WP-CLI on a Plesk server
- Upload the file using either SFTP or Plesk File Manager (it’s simplest to upload the file to the domain’s web root folder. How to find the web root is described in both of those guides).
- Run the import command:
php wp-cli.phar import [my_filename].xml --authors=create
If you have multiple XML files (like one for posts and one for media), repeat the import command for each of them.
If there is any problems during the import (like the process is killed) you can always re-run it. In all cases where I’ve had to do this, the import utility has skipped over existing imported items and resumed where it left off.
That’s it! This guide shows you how to import your WordPress XML exports by using CLI to avoid web server timeouts.