To copy a WordPress website for local testing, first download your website files, export the database and import both into a local environment such as XAMPP. Next, update the database connection 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 environment or create a reusable duplicate of your site for other purposes:

  • For a manual local testing environment, XAMPP is a suitable option. XAMPP is an Apache distribution 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 automatically creates a WordPress environment and provides additional 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 phpMyAdmin are applied immediately and usually cannot be reversed automatically.

Keep in mind that a local copy of your live website may contain personal data, including comments, form submissions or customer information. Only use trusted devices and anonymise production 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 environment in the web directory on your computer. With a standard XAMPP installation, 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 installation. Using an FTP program such as FileZilla, copy all files from your existing WordPress installation 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 installation uses, you can find this information in your IONOS customer account before copying or duplicating 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 installation, click ‘Manage website’.
  4. Open the settings.
  5. Under ‘Advanced settings’, open phpMyAdmin.
  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 duplicating 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 environment 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’.

phpMyAdmin 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 environment and copy or duplicate your WordPress website, you first need to update the siteurl and home values.

  1. In phpMyAdmin, open the options table of your WordPress installation, usually wp_options. If your installation uses a different table prefix, the table name will vary accordingly, 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 installation. Other references to your live domain, such as in posts, metadata, widgets or serialised data, must be updated separately 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 credentials for your live website, which must be replaced with the details of your local database so that your copied or duplicated WordPress website can connect correctly.

  1. Open the folder containing your local WordPress installation. 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 installation, 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 individually secured installations may use different credentials. Once you have entered the correct details, save the file.

The links in your local WordPress installation may still point to your live website. One way to update them is with the Better Search Replace plugin. Alternatively, advanced users can use WP-CLI when they copy or duplicate a WordPress website. Whichever method you choose, make sure it can handle serialised 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 installation, 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 replacement field, for example http://localhost/wp-test-environment.
  6. Select the tables belonging to your WordPress installation.
  7. Start the replacement process.

If you prefer to use WP-CLI to copy a WordPress website, you can use the officially documented 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 processing, which can be useful for complex or serialised 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 replacements shown looks reasonable, 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 installation, 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 sufficient.

Step 10: Use the local WordPress installation

To use your local WordPress installation after copying or duplicating 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 installation as usual. If the website does not work correctly, check the following:

  • Have all references 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 environment.

Go to Main Menu