Home Articles Platform info WordPress How to duplicate a WordPress site

How to duplicate a WordPress site

Time needed: 15 minutes.

Included with our service is a sitecopy script, that allows you to very easily duplicate a website. The sitecopy script makes a full copy of all files for a website and sets up the connection to a new database. It’s a fast and easy solution!

  1. Add a new site

    Start by adding an additional website with us. To add a new site in our admin panel, click the plus-sign next to “SITES”. Then select a Site name and click the “Create new site” button. You’ll see a confirmation and receive an email with SSH/SFTP and database information for the new website.

  2. Login using SSH/terminal

    Login by SSH to the new website. Change directory to /public   and remove our default index page, like this:

    cd public
    rm index.php


    Now you need to make sure you have the user info for the website that you want to clone FROM. You need the SSH/SFTP username, password and the server address to clone FROM. You also need the database name, username and password to clone TO (this is sent to you by email, when you set up the new website).

  3. Run the sitecopy script

    Run our sitecopy software, like this:

    sitecopy -t wp [email protected] database-to-clone-to -k -e wp-content/uploads

    First we define the type of website to copy (-t wp , meaning type=WordPress). Then we set the user/server to clone FROM. Then we set the database to clone TO. With the -k flag, we create a temporary SSH key (to avoid having to repeat the password). Finally we exclude copying the folder wp-content/uploads with the -e flag.

    Excluding the wp-content/uploads  folder is not a must, but a recommendation. You can do this if you don’t want to store multiple copies of your uploaded files (primarily images). The new website will still work with the images, since we’ll rewrite these through .htaccess  (in the final step of this guide).

    If you want to copy all folders/files, feel free to remove the “-e wp-content/uploads ”. Just make sure you have enough storage space for this in your package.

    When you run the sitecopy software, you will need to enter the password for the user to clone FROM. You’ll also need to enter the user info for the new database. Other than that, the sitecopy software will manage the whole copying process and database setup for you.

  4. Update the URL

    Now you need to correct the address to the new website in the database. This is easily done with WP-CLI, like this:

    wp search-replace https://website-that-we-cloned-from https://website-that-we-cloned-to --all-tables

    The new website address with us can be found in our admin panel, if you select the website and click the “Domains” tab.

    Note: If you have a WordPress network installation (WordPress Multisite), you also need to update the address in the database tables wp_blogs and wp_site, and in the WordPress configuration file wp-config.php  (if it’s the main address).

  5. Update .htaccess (optional)

    Note that this step only applies if you excluded the wp-content/uploads folder. If that is the case, we need to setup .htaccess  to rewrite the wp-content/uploads folder  (for the images), like this:

    nano -w .htaccess

    Add the following lines:

    Use uploads folder from production site
    RedirectMatch 301 /wp-content/uploads/(.*) https://website-that-we-cloned-from/wp-content/uploads/$1

    To close and save the .htaccess  file, click ctrl+x, select y (to save) and press the Enter-key.

    Now you can visit the new website that you’ve set up, which will be an exact copy of your real/production website.

Did this help you?