This tutorial assumes you have some prior knowledge of PHPmyAdmin, adding Domains, and copying files.
How-to Create a WP Staging Website:
1. First thing you need to do is to create a subdomain (subdomain.example.com). This allows your staging website to run in a separate folder, not affecting your main website files.
2.Now that you have setup your subdomain, the next step is to copy the database from your live site to your staging site.
Log into phpMyAdmin, and select your current live database, clicking on the Operations tab in the menu bar.
In the Copy Database To box, enter the name of your staging database (if you haven’t created it yet, click “CREATE DATABASE before copying”). Click Go to run the copy, this could take longer on larger databases.
3. After your database has copied, you need to select it from the sidebar on the left and rename the URLs in the database. To do this, click on the SQL tab in the menu bar and add the code below to Run SQL queries.
Remember to update the URL value: NEW_URL = staging.example.com, ORIGINAL_URL = example.com
UPDATE wp_options SET option_value = REPLACE(option_value, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_posts SET guid = REPLACE(guid, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'ORIGINAL_URL', 'NEW_URL');
4. After copying your database, you need to copy your WordPress files to the staging server.
5. After copying your data, update your wp-config.php file to use your new staging database connection details. You can use FTP to accomplish this, or if you are an expert, you can use Terminal:
cp -a /PATH/TO/INSTALL /PATH/TO/STAGING
6. Remember to add a disallow all to your robots.txt, and/or update your Search Engine Visibility settings or you might be penalized with duplicate content.
Settings > Reading > Search Engine Visibility
Click “Discourage search engines from indexing this site”