FAQ Migrations & Transfers

How to copy a site to a subdomain for testing

A subdomain copy gives you a real, public URL to test changes on without touching the live site at all.

Updated 5 min read Intermediate

A subdomain copy — something like staging.yourdomain.com — gives you a real, reachable web address to test on without going anywhere near the live site. It is useful for trying a big change, testing a migration's file and database copy before committing to it, or letting someone else review work before it goes live, and it is a different tool from the hosts file trick used to preview a completely different server.

Setting it up

  1. Create the subdomain in your control panel, which gives it its own folder on the server.
  2. Copy the live site's files into that folder.
  3. Create a separate database for the copy — never point a test copy at the live database, since anything it writes will affect the real site.
  4. Import an export of the live database into the new one.
  5. Update the copy's configuration file with the new database name, user and password, so it points at its own database rather than the live one.

Block it from search engines

A subdomain copy is a real, public URL, which means search engines can find and index it if nothing stops them — and a duplicate of your entire site sitting at a different address is not something you want turning up in search results. Add a robots.txt file to the subdomain that disallows everything, and consider password-protecting the folder as well if the content is sensitive or unfinished:

User-agent: *
Disallow: /

Test freely, then decide what to do with it

Because the subdomain copy has its own database, changes made there — testing a plugin, trying a new theme, checking how an update behaves — have no effect on the live site whatsoever. This is the whole point: it is a safe place to break things.

What you do afterwards depends on why you made the copy:

  • Testing a migration's file and database copy — once satisfied it works, you would typically move on to testing directly on the destination server via a hosts file entry rather than keeping a permanent subdomain copy. See previewing a site with your hosts file for that step.
  • Testing a change before applying it to the live site — once confirmed, you would repeat the change on the live site directly, or, for a database change, export the subdomain's database and import it over the live one.
  • Keeping a permanent staging area — some sites keep a subdomain copy running long-term for ongoing testing before changes reach production, in which case leave it in place but keep the robots.txt block and password protection permanently too.
Do not forget the copy is there

An old test subdomain, left live and forgotten, is a duplicate of your site sitting on the internet with nobody checking it for security updates. If you only needed it temporarily, remove it once you are done rather than leaving it running indefinitely.

Testing before a full migration?

For moving a site to entirely new hosting rather than testing on a subdomain of the same account, our full migration guide covers the process end to end, and the service is included free with our hosting plans — get in touch if you would like it done for you.

Related reading