To copy a WordPress website for local testing, first download your website files, export the database and import both into a local en­vir­on­ment such as XAMPP. Next, update the database con­nec­tion details, site URL and internal links to match the local setup. This allows you to safely test plugins, updates and changes without affecting your live website or when creating a duplicate of your WordPress site.

Step 1: Prepare your WordPress website

Before you copy a WordPress website and create a local version, decide which method best suits your needs. The right approach depends on whether you want to set up a manual test en­vir­on­ment or create a reusable duplicate of your site for other purposes:

  • For a manual local testing en­vir­on­ment, XAMPP is a suitable option. XAMPP is an Apache dis­tri­bu­tion that includes MariaDB, PHP and Perl. On Windows, it is often installed under C:\xampp\, although the path may vary depending on your setup.

  • If you want to simplify the setup process, a tool such as Local may be a better choice. It auto­mat­ic­ally creates a WordPress en­vir­on­ment and provides ad­di­tion­al features such as WP-CLI, flexible PHP versions, and import and export functions.

Before exporting your site to copy or duplicate a WordPress website, create a complete backup of both your files and database. Changes made to a database in phpMy­Ad­min are applied im­me­di­ately and usually cannot be reversed auto­mat­ic­ally.

Keep in mind that a local copy of your live website may contain personal data, including comments, form sub­mis­sions or customer in­form­a­tion. Only use trusted devices and anonymise pro­duc­tion data where possible before testing when you duplicate a WordPress website.

Note

The steps described here are based on a Windows system. However, the process is largely the same on macOS or Linux. The example website used for local testing is hosted on IONOS servers, and XAMPP is already installed.

Step 2: Download WordPress files

First, create a new folder for your local test en­vir­on­ment in the web directory on your computer. With a standard XAMPP in­stall­a­tion, this is usually the C:\xampp\htdocs\ folder. Create a new folder there, for example wp-test-environment.

Make a note of this folder name, as you will need it later to access your local WordPress in­stall­a­tion. Using an FTP program such as FileZilla, copy all files from your existing WordPress in­stall­a­tion into the newly created folder.

If your website contains a large amount of data, this process may take some time.

Step 3: Identify the database

If you do not know which database your WordPress in­stall­a­tion uses, you can find this in­form­a­tion in your IONOS customer account before copying or du­plic­at­ing your WordPress website:

  1. Log in to your IONOS customer account.
  2. In the title bar, select ‘Menu’ → ‘Websites & Shops’.
  3. In the tile for your WordPress in­stall­a­tion, click ‘Manage website’.
  4. Open the settings.
  5. Under ‘Advanced settings’, open phpMy­Ad­min.
  6. Note down the name of the database.

Step 4: Export the database

In the next step, export the database of your live website. With IONOS, you can also do this via your customer account before copying or du­plic­at­ing your WordPress website:

  1. In the title bar, click ‘Menu’ → ‘Hosting’.
  2. In the ‘Databases’ tile, click ‘Manage’.
  3. Click ‘Open’ next to the desired database.
  4. In the menu bar, click ‘Export’.
  5. To start the export, click ‘OK’.
  6. Save the export file on your computer.

Make a note of the file name and storage location of the exported database file. You will need it later when importing the database into your local en­vir­on­ment to copy or duplicate your WordPress website.

Step 5: Import the database

To copy a WordPress website or create a duplicate, you must import the exported database into a new, empty database on your local web server.

  • Start the XAMPP Control Panel program.
  • Start Apache and MariaDB (labelled as ‘MySQL’ in the Control Panel).
  • Next to ‘MySQL’, click ‘Admin’.

phpMy­Ad­min will then open. Follow these steps to import the database:

  1. Click ‘Databases’.
  2. Enter a database name and click ‘Create’.
  3. Select the newly created database.
  4. Click ‘Import’.
  5. Select the database file you exported earlier.
  6. Start the import.

Once the import is complete, a local copy of your WordPress database is available.

Step 6: Adjust the local database

After importing the database, your local copy still contains the URL of your live website. To make WordPress work correctly in your local en­vir­on­ment and copy or duplicate your WordPress website, you first need to update the siteurl and home values.

  1. In phpMy­Ad­min, open the options table of your WordPress in­stall­a­tion, usually wp_options. If your in­stall­a­tion uses a different table prefix, the table name will vary ac­cord­ingly, for example abc_options.
  2. Find the siteurl and home entries.
  3. Edit both values and replace the live URL with your local URL, for example: http://localhost/wp-test-environment.
Note

These two entries only define the base URL of your local WordPress in­stall­a­tion. Other ref­er­ences to your live domain, such as in posts, metadata, widgets or seri­al­ised data, must be updated sep­ar­ately using search and replace if you want to copy or duplicate a WordPress website. Tools such as Better Search Replace or WP-CLI are suitable for this task.

Step 7: Adjust files

Normally, you will now need to edit the wp-config.php file. It still contains the database cre­den­tials for your live website, which must be replaced with the details of your local database so that your copied or du­plic­ated WordPress website can connect correctly.

  1. Open the folder con­tain­ing your local WordPress in­stall­a­tion. In this example: C:/xampp/htdocs/wp-test-environment.
  2. Open the wp-config.php file in a text editor.
  3. Replace the existing database details with those of your local database.

With a standard XAMPP in­stall­a­tion, the settings are often as follows:

  • DB_NAME: Name of your local database
  • DB_USER: root
  • DB_PASSWORD: leave blank
  • DB_HOST: localhost

These values may differ depending on your local setup. The settings above are commonly used with XAMPP, but other tools or in­di­vidu­ally secured in­stall­a­tions may use different cre­den­tials. Once you have entered the correct details, save the file.

The links in your local WordPress in­stall­a­tion may still point to your live website. One way to update them is with the Better Search Replace plugin. Al­tern­at­ively, advanced users can use WP-CLI when they copy or duplicate a WordPress website. Whichever method you choose, make sure it can handle seri­al­ised data correctly. For this reason, you should not simply replace URLs directly in the database using a basic search-and-replace function.

Proceed as follows:

  1. Open the admin area of your local WordPress in­stall­a­tion, for example at http://localhost/wp-test-environment/wp-admin.
  2. Install and activate the Better Search Replace plugin.
  3. Open the plugin settings under Tools.
  4. Enter the URL of your live website in the ‘Search for’ field.
  5. Enter the local URL in the re­place­ment field, for example http://localhost/wp-test-environment.
  6. Select the tables belonging to your WordPress in­stall­a­tion.
  7. Start the re­place­ment process.

If you prefer to use WP-CLI to copy a WordPress website, you can use the of­fi­cially doc­u­mented wp search-replace command. First run the command with the --dry-run flag to preview the changes without modifying the database. It is also advisable to use --skip-columns=guid to prevent the GUID column in the posts table from being changed. The --precise flag uses more thorough PHP-based pro­cessing, which can be useful for complex or seri­al­ised data, although it is slower.

wp search-replace 'https://your-live-domain.com' 'http://localhost/wp-test-environment' --skip-columns=guid --precise --dry-run
bash

If the number of re­place­ments shown looks reas­on­able, run the command again without --dry-run to apply and save the changes.

wp search-replace 'https://your-live-domain.com' 'http://localhost/wp-test-environment' --skip-columns=guid --precise
bash

After updating all URLs, save the permalink settings again:

  1. In your local WordPress in­stall­a­tion, go to ‘Settings’ → ‘Permalinks’.
  2. Save the currently selected permalink structure again.

This refreshes the rewrite rules. You usually do not need to change the permalink structure to ‘Post name’. Simply saving the existing structure again is suf­fi­cient.

Step 10: Use the local WordPress in­stall­a­tion

To use your local WordPress in­stall­a­tion after copying or du­plic­at­ing your website, follow these steps:

  1. Start the XAMPP Control Panel.
  2. Start Apache and MariaDB (labelled as ‘MySQL’ in the Control Panel).
  3. Open your local website in your browser, for example at http://localhost/wp-test-environment/.
  4. To access the admin area, go to http://localhost/wp-test-environment/wp-admin.

You can then use your local WordPress in­stall­a­tion as usual. If the website does not work correctly, check the following:

  • Have all ref­er­ences to the live URL been replaced?
  • Are any caching plugins still using old paths?
  • Are there redirects in .htaccess or in plugin settings that still point to the live domain?
  • Are any external resources still being loaded from the live website?

These are common sources of errors after migrating a WordPress website to a local en­vir­on­ment.

Reviewers

Go to Main Menu