How to Clone a Live WordPress Site to Your Laptop Over SSH

· 3 min read · by Lennart de Ridder

You have a live WordPress site and you want a working copy on your laptop: to fix a bug without touching production, to try a plugin update, or to start redesign work. Doing it right means copying the files, copying the database, and changing every URL in that database from the live domain to a local one. This post shows the manual way with SSH and WP-CLI, then the same thing in SiteShift, and the gotchas that apply to either.

What a clone needs

  • SSH access to the host, or at least SFTP for the files and a way to export the database.
  • The remote webroot, the folder that contains wp-config.php.
  • The live URL, so it can be replaced with the local address in the database.
  • A local PHP and database that match the live site closely enough to run it.

The manual way

  1. Log in over SSH and export the database from the remote webroot: wp db export dump.sql. Without WP-CLI on the server, mysqldump with the credentials from wp-config.php does the same.
  2. Download the dump and the wp-content folder with rsync or SFTP. On a site with years of uploads this is the slow part.
  3. Create a local site and import the dump.
  4. Run wp search-replace from the live URL to the local URL. Use WP-CLI for this and not a text editor, because WordPress stores settings as serialized PHP and a plain replace corrupts it (details).
  5. Fix wp-config.php for the local database and set debug options as you like.

The same thing in SiteShift

In SiteShift the New site screen has a “Clone from remote” tab. You fill in the SSH host, port and user, choose password or key authentication, and give the remote webroot and the production URL. There is a connection test, so you find out about a wrong key or port before anything is copied. Pick a local name and a PHP version, and SiteShift copies the files and the database over SSH into a new local site, with the database URLs rewritten to the local address.
If your site is on one of the hosts with a connected account, you can start from the Hosting screen instead and the SSH details are prefilled. The integration pages list the settings for Hostinger, TransIP, SiteGround, Hostnet and DigitalOcean.
Once the site exists locally, the same connection is used for pushes and pulls, with a review screen before anything goes back. That part is the reason I built it, and the developer page has more on it. A clone needs SSH access, which some shared hosting plans leave off, and SiteShift is paid (€9/month excluding VAT) and runs on macOS with Apple Silicon and on Windows.

Things to check on a fresh clone

  • Mail: a local copy of a live site can send real emails (order mails, newsletters, form notifications) to real people. Disable outgoing mail or point it at a local mail catcher before you click around.
  • Payments and integrations: WooCommerce, CRM and API plugins may still hold live keys. Switch them to test mode or remove the keys locally.
  • Caching and security plugins: they can break on a new domain. Deactivate them locally if the site will not load.
  • Licence keys: some premium plugins tie a licence to a domain and may complain on a .localhost address. That is normal.
  • Search engines: never push local settings back that say “discourage search engines”, and never leave the real site reachable on two addresses.
  • Size: a large uploads folder makes the first clone slow. Plan for that, and consider whether you need all the media locally.

If you are moving the site to a different host rather than copying it for work, the checklist in moving a WordPress site to a new host covers DNS, SSL and mail as well.

L
Lennart de Ridder

Builds SiteShift and runs DeveloKey, a WordPress agency in Leiden. Every guide here comes from running client sites through the same tool.

Local WordPress with bundled PHP and MySQL, pushed to any host over SSH.

Get SiteShift — €9/mo