Clone a WordPress Site Without Admin Access
Hosting access outranks wp-admin: a clone is the files plus a database dump. The real work is the handful of values that must change in the copy so it stops pointing at, mailing from and pinging as the live site.
You do not need wp-admin to clone a site: copy the files, dump the database, then change the dozen values that still point the copy at the live site. This is for people who own the site, like the person paying for hosting or the business that inherited it. If you cannot get into the hosting account either, you need account recovery with the host, and no technical route replaces that.
Before doing anything by hand, check the hosting panel for staging, clone or copy to subdomain. They need no WordPress login, but the checklist below still applies to what they produce.
What you need
- File access: SFTP, SSH, or the panel's file manager.
- Database access: phpMyAdmin, Adminer or the
mysqlclient. The credentials are inwp-config.phpasDB_NAME,DB_USER,DB_PASSWORDandDB_HOST, so reading that file is enough to get in.
Note $table_prefix while you have the file open. It is often not wp_, and it matters later.
Copy the files and the database
Archive the whole WordPress root on the server, including wp-config.php and .htaccess, and download one file instead of tens of thousands.
With SSH, export from the WordPress root with either command:
wp db export site.sql
mysqldump --single-transaction -u DB_USER -p DB_NAME > site.sql
In phpMyAdmin, select the database, then Export and take every table. A dump cut off by a timeout can import without complaint and leave content missing. For a mysqldump file, tail -n 1 site.sql should print -- Dump completed on ….
Build the clone
- Create the destination with its own empty database and database user. Sharing the live database with another prefix is possible, but it is where clones go wrong (see the prefix row below).
- Upload and extract the files, then import the dump:
wp db import site.sql, ormysql -u NEW_USER -p NEW_DB < site.sql. - Edit the clone's
wp-config.phpbefore loading any page. The first rows of the checklist come before the first request, because one page view can trigger cron.
Rewrite the URLs without breaking serialized data
WordPress stores options, widgets and theme settings as serialized PHP, for example s:22:"https://oldsite.com/up";, with the byte length in front. A raw SQL REPLACE() changes the text but not the length. maybe_unserialize() then gets false back and the setting quietly falls back to its default. WP-CLI recalculates the lengths:
wp search-replace 'https://oldsite.com' 'https://clone.example.com' --all-tables --skip-columns=guid --dry-run
Read the counts, then run it again without --dry-run. Three details catch people out:
- Variants. Run it again for
http://oldsite.comand, if the site was ever onwww, for that host too. Do not replace the bare domain:oldsite.comon its own also rewrites addresses likeinfo@oldsite.com. - Escaped JSON. Core block attributes are saved with unescaped slashes, so the plain URL matches them. Some plugins, page builders among them, store JSON with escaped slashes. A dry run for
https:\/\/oldsite.comshows whether any such rows exist. --skip-columns=guid. A post's GUID is an identifier, not a link, and feed readers use it. Leave it alone.
Without SSH, use a serialization-aware search-replace script, then delete it straight away.
The clone checklist
| What | Where | Change it to | Verify |
|---|---|---|---|
DB_NAME, DB_USER, DB_PASSWORD, DB_HOST |
wp-config.php |
the clone's database | Site loads; no "Error establishing a database connection" |
$table_prefix |
wp-config.php |
the same prefix as the dump | No "table doesn't exist" errors |
WP_HOME, WP_SITEURL |
wp-config.php, if defined |
the clone URL, or remove them | wp option get home prints the clone URL |
home, siteurl options |
{prefix}options |
done by search-replace | wp option get siteurl |
| URLs in content, meta, serialized settings | all tables | done by search-replace | A second --dry-run reports 0 replacements |
DISABLE_WP_CRON |
wp-config.php |
true |
Scheduled posts stay scheduled on the clone |
| Outgoing email | a must-use plugin | add_filter( 'pre_wp_mail', '__return_false' ); |
A password reset request shows "The email could not be sent" |
WP_ENVIRONMENT_TYPE |
wp-config.php |
'staging' |
Publishing sends no pingbacks |
| Keys and salts | wp-config.php |
new values (wp config shuffle-salts) |
A live-site login cookie does not work on the clone |
admin_email |
{prefix}options |
your address | wp option get admin_email |
blog_public |
{prefix}options |
0 |
Page source shows noindex, nofollow |
| Payment, API and webhook keys | plugin settings | test or sandbox keys | No live charges or webhooks from the clone |
Why some of these rows matter:
WP_HOMEandWP_SITEURL. These constants override the two options every time they are read and never write to the database. If the livewp-config.phpdefines them, the clone keeps sending you to the live site whatever the database says. As a stopgap they can make the clone load, but they fix nothing else. More in WP_HOME and WP_SITEURL.- The table prefix is stored inside the data. The roles option is named
{prefix}user_roles, and each user's role sits in usermeta under{prefix}capabilitiesand{prefix}user_level. Change$table_prefixwithout renaming those rows and every account loses its role, administrators included. Keep the prefix unless you have to change it. If tables seem to be missing, see table doesn't exist. - Email.
pre_wp_mailruns at the start ofwp_mail(), so it also covers SMTP plugins that configure PHPMailer. It does not cover a plugin that replaceswp_mail()or calls its own mail API. Check those in their settings. Howwp_mail()works is in wp_mail(). - Environment type. In WordPress 7.1, any value other than
productionturns off outgoing pingbacks, trackbacks and ping services. A clone left on the defaultproductionwill ping every site the copied posts link to. blog_public = 0adds anoindex, nofollowrobots meta tag to every page. It does not addDisallow: /torobots.txt, so put HTTP authentication in front of the clone too if the host offers it.
If the clone sits in a subdirectory, the .htaccess rules need that path in RewriteBase and in the final RewriteRule. Re-saving permalinks writes them if the file is writable.
Get your admin account back
On the clone, create a new administrator rather than guessing the old password:
wp user create yourname you@example.com --role=administrator
WP-CLI prints a generated password. Without SSH, add an administrator through phpMyAdmin. That method depends on the prefixed capabilities key described above. Once it works on the clone, repeat it on the live site.
Verify
- Log in, open Settings › Permalinks and save, then load a post, an archive and an image from
/wp-content/uploads/. wp search-replace 'oldsite.com' 'x' --all-tables --dry-runshows what still mentions the old domain. Expect email addresses and GUIDs. Look at anything else.wp cron event listshows the copied queue. WithDISABLE_WP_CRONset, overdue events pile up there instead of running.
Then fix what caused the lockout: schedule a proper backup and keep the hosting credentials somewhere that survives a staff change. If the goal is moving the site rather than copying it, continue with migrating to a new host.
Frequently asked
- No. The files hold the theme, plugins and uploads, but every post, page, setting and user lives in the database. A file-only copy is an empty install wearing the right theme. The database credentials are in wp-config.php, so file access usually gets you database access too.
- Options, widgets and theme settings are stored as serialized PHP, which records each string's byte length. Change the URL without changing the length and unserialize fails, WordPress gets false back, and the setting silently falls back to its default. WP-CLI's search-replace rewrites the lengths.
- Yes, unless you stop it. The database brings the full cron queue and every plugin's email settings with it, so the copy can send order, newsletter or reminder emails to real people. Disable WP-Cron and short-circuit wp_mail() on the clone before you load any page.