Clone Site

If you’re moving a site to another server in your SpinupWP account, you should use the Move Site tool as it clones your site to another server with fewer steps, saving you time.

If you’d like to clone the contents of your site into an existing site within your SpinupWP account, you should use the Refresh Site tool as it migrates your site’s files and/or database to an existing site with fewer steps, saving you time.

The Site Clone tool allows you to quickly create a complete copy of an existing site on SpinupWP, which includes all files, the database, and server configuration (Nginx and PHP-FPM). Cloning is useful for creating staging sites or for quickly testing server configuration changes. For example, you could test upgrading your site to a newer version of PHP in an isolated manner without impacting your production site.

To clone a site, head over to the site’s settings screen and click Clone Site in the top right corner.

Clone Site feature

This will open the Clone Site screen, where you can configure the new domain, database, and site settings (PHP version, page cache). For git-based sites, you will also be able to select the new branch to check out and modify your deploy script (if required).

Clone Site wizard

When a site is cloned, the following actions are performed:

  • Create new site user
  • Install selected PHP version (if not already installed)
  • Copy existing PHP pool config
  • Find & replace the domain in the PHP pool config file
  • Copy all existing Nginx config files to the new domain directory
  • Find & replace the domain in all Nginx configs
  • Symlink new sites-available config file
  • Copy all site files (including git files) to the new domain directory
  • Checkout selected branch (if git site type)
  • Copy cron config (including custom cron entries)
  • Find & replace the domain in cron
  • Copy logrotate config
  • Find & replace the domain in logrotate config
  • Copy database
  • Update database credentials in wp-config.php or .env
  • Find & replace the URL in the cloned database
  • Enable HTTPS (if enabled)
  • Enable the page cache (if enabled)
  • Reload Nginx
  • Reload PHP-FPM

After cloning a site, we recommend you test your site thoroughly and check any Nginx config files you might have added or customized.

Once a site has been cloned, it functions like any other site in SpinupWP.

Unable to update site’s wp-config.php file

If, after cloning your site, you’re presented with the following error message, you must manually update your database credentials. It’s vitally important that you manually do this, otherwise, your cloned site may be using the original site’s database. Meaning, changes made to your cloned site may impact your original site.

Clone Site error message

SpinupWP will try to determine where your database credentials are stored. For most sites, this will be your wp-config.php file. However, for git-based sites, it’s common to use a .env file.

When attempting to update your database credentials, SpinupWP will first look for a .env file in your site’s files directory (/sites/{DOMAIN}/files/.env). If this file exists, SpinupWP will look for a DB_NAME environment variable. If a .env file is found but no DB_NAME environment variable exists, SpinupWP will show the above error message. Using SSH or SFTP, you will need to update your .env file to reflect the new database credentials.

DB_NAME='cloned_database_name'
DB_USER='cloned_database_user'
DB_PASSWORD='database_password'

If your site does not have a .env file, SpinupWP will recursively search your site’s PHP files (excluding wp-config-sample.php, *.sample.php, and setup-config.php) for the DB_NAME constant. If more than one match is found, SpinupWP will show the above error message. Using SSH or SFTP, you will need to update your wp-config.php file to reflect the new database credentials.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'cloned_database_name' );

/** MySQL database username */
define( 'DB_USER', 'cloned_database_user' );

/** MySQL database password */
define( 'DB_PASSWORD', 'database_password' );

Once you’ve updated your database credentials, we recommend that you perform a find and replace on the cloned database. This will ensure that your links are updated to reflect the new domain name. You can use WP-CLI to do this:

wp search-replace '//old_url' '//new_url' --network
wp cache flush

Refreshing the Cloned Site

In time you may want to synchronize the new cloned site with the original site it was cloned from. This can be accomplished using the Refresh Site tool which allows for any site’s files and/or database to be updated from another site within your SpinupWP account.