A quick easy way to do this even if your webhosting doesn’t have a 1-click option.
There are only 8 steps:
- Add domain (or subdomain) to your webhosting account (if needed)
- Copy the files
- Copy the database
- Create new database user and add permissions (optional)
- Edit database credentials in wp-config.php
- Edit “siteurl” and “home” rows in
wp_options
database table - Add A record for new site domain to your DNS settings (if needed)
- Manually rewrite URL strings in database
This manual method is actually simple enough to do and actually my preferred method for large or critical sites. I don’t like to trust automated scripts or plugins, although they are convenient and probably fine for most cases.
STEP #1 – add domain (or subdomain) to webhosting account
This step can vary between different webhosts. Some of them require you to add the domain to your account before you can create a site on it. Others let you choose the domain as you’re creating the site.
On cPanel:
- Go to Addon Domains (if new site is a root domain “domain.com”)…or Subdomains (if new site is a subdomain “staging.domain.com”).
- Type in the new domain or subdomain, and add it.
STEP #2 – copy the files
Now you copy the files from the original website directory to the new site directory.
If the new site will be hosted on the same server:
- You can use your webhosting’s File Manager function to copy them to the new directory.
- Make sure to click on the “Settings” button in File Manager (it’s at top-right for cPanel), and select “Show hidden files”. You need this to see .htaccess files.
- Then select all files and folders (except “.well-known” and “cgi-bin”), then click “Copy” and type in the directory name for the new site.
If the new site will be hosted on another server:
- Highlight all the files in File Manager (just like in previous step) but this time click on “Compress” or “Archive”. Pick the GZIP TAR archive option (it’s smallest size and safest for Linux file format, IMO).
- Once the compression is done, download the ZIP file that was created.
- Then upload on the new server and extract it in the new website directory.
If your webhost doesn’t have a File Manager feature, there are several ways to copy files:
- FTP – probably not my favorite (especially if you have many files) but it works.
- SSH – best option if you know how to use the command line, but too technical for most people.
- BACKUP – most webhosts will have a handy backup function that can archive all files and databases for a site for you.
Anyway, just get the files copied to the new website directory and we continue on…
STEP #3 – copy the database
Create the new database:
- Use your webhost function to create new database.
- For those on cPanel, go to MySQL Databases, type in the name, and click “Create New Database”.
- Usually, you try to put a helpful name. Like the domain and the word “live” or “staging” right after it.
- For those on other control panels, follow their guides to create new database.
Export the original database:
- Go to phpMyAdmin, click on the original site database (on left panel).
- Then click Export tab.
- For most sites, you can just click “Go” and it immediately downloads the exported database.
- If you have a large database (anything over 100mb), it might be better to click “Custom” then scroll down to Compression and pick “gzipped”, then click “Go”.
- If you have a really large database, please follow my tactics for moving large sites.
Import original database to new database:
- From phpMyAdmin, select new database (on left panel).
- Then click Import tab.
- Choose the database file from your computer, and click “Go”.
Want a pro tip? You can actually create and clone a database all at once directly from phpMyAdmin (good to know in the future for same-server clones):
- Select the database from left-side.
- Click the Operations tab.
- Scroll down to “Copy database to:”.
- Type in the name.
- Select Structure and Data
- Check CREATE DATABASE before copying (if you haven’t already).
- Check Add AUTO_INCREMENT value.
- …and click “Go”.
STEP #4 – edit site URL in database
From phpMyAdmin:
- Select new database (on left-panel).
- Scroll to the
wp_options
table. (You might have different prefix than “wp”.) - Look for the rows with “siteurl” and “home” in the option_name column. It’s usually near the top might be buried a little further in large databases.
- Change the site address to the new one. You can do this by double-clicking the option_value block or clicking “Edit” on the left of the row.
In some cases, the site URL is manually defined in wp-config.php. If so, it will override what is put in the database and should be changed from the wp-config.php file instead. We’re going there soon anyway.
STEP #5 – edit database credentials wp-config.php file
Open up the wp-config.php file:
- If using cPanel or other full-featured panels, you can do it from File Manager function. If using FTP, you have to download the file and then edit and then upload it back.
- Navigate to the new site directory and edit the wp-config.php.
- Once inside wp-config.php, scroll down to the database name and change it to the new one.
- From here you can decide whether to use the same database user name or not. (Many people will put a new database user as well for maximum security.) Most people will put the same database username as the database name. It’s easier to remember and decrease chances of mistake this way.
This is also a good time to see if the site address was manually defined in the wp-config file anywhere. Scroll from top to bottom just to check.
STEP #6 – create new database user and add permissions (optional)
If you choose to use a new database user in the previous step, then you have to create it now:
- Go to your webhosting database manager. (In cPanel, it’s MySQL Databases.)
- Put in the database username and password.
- And click create.
- Then scroll down further and the new database user to the new database.
- When you get to the permissions screen, make sure to select ALL PRIVILEGES.
STEP #7 – add A record for new site in DNS settings (if needed)
If your webhosting automatically handles DNS already (common with most shared hosting plans), you don’t have to do anything here. Just skip this step.
If you’re using a server panel or webhosting service that doesn’t manage DNS, or you’re using a 3rd-party DNS service (like Cloudflare)….
- Log into your DNS service (Cloudflare).
- Go to the DNS settings tab.
- Create an “A” record for the domain or subdomain, and point it to the server IP.
STEP #8 – manually rewrite URL strings in database
Once your DNS has finished propagating (hopefully soon), you should be able to log into your new site.
Now we have to update all the urls in your database so that every link in your site points to the new site url instead of the old one:
- Log into wp-admin.
- Install either Better Search Replace or WP Migrate DB. Both work well and sometimes one works better than the others. BSR has the advantage that you can manually select which tables.
- Go to Tools > and pick the database plugin you installed from previous step.
- If using BSR: put “//oldsite.com” in Search for and “//newsite.com” in Replace with. Select all tables, and uncheck “Run as dry run”. Then click Run Search/Replace. If you have page errors, try selecting fewer tables at a time.
- If using Migrate DB: select Find and Replace. Put “//oldsite.com” in Find and “//newsite.com” in Replace. Delete any other Find/Replace rows and click Export.
Congratulations, you are done!
- You can use these same steps to migrate sites.
- If migrating, you don’t need to do the last step (#8).
Jesse Distad
Coupe things to add… rsync… and do the DB modifications when you export, that way you have everything all set and just upload the new database, I’ve found it’s much less likely to have errors when doing a modify on export compared to doing it on a live/in use db 🙂
Johnny
I agree 100% and now also added a link to my other guide for migrating large sites. It’s just tricky to teach beginners how to modify DB on export.
Chamari Reid
I followed step by step of your article.
I copied domain site to subdomain called dev. Created a mysql database and imported data from domain database.
When I try to access url dev.mydomain.org from the browser, it takes me to a site called aagr.org.uk. Why is that happening?
Johnny
I have no idea what went wrong without seeing your setup for myself. Make sure your site url isn’t overridden in wp-config.php? Or maybe other redirects in place?
Chamari Reid
Hi Johnny, Thank you for your time. I cleared the browser cache and it started working.
Do you have instructions on how to replace the live website with cloned site?
Johnny
My guide should work whichever way you want to clone.