For most webmasters running websites growing quickly, they are required to make more changes on the site and booked for some mistakes. If you are one of those people and don’t wish to make such embarrassing situation happen to your live site, then you might as well have a try on staging environment, which is recognized as a great option for testing out newer version of software so as to make all changes go with the production site properly.
Since many readers get confused what is staging environment and how to make a good use of it, we make this guide to give answers to you. Before everything, let’s get started to involve in a brief introduction on staging environment.
What Is Staging Environment?
Generally speaking, a staging environment is a clone of your website that enables you to make any changes on it and test if all things go well. For example, if you plan to update a plugin and wish to test whether the latest version applies to your website, then you can update this plugin in a staging environment before allowing it for your live site.
If everything works well, you can make the newer version available for your production site. Otherwise, you need to seek some other ways to do so. Besides, the themes and custom code can also be included in the test. After making some changes on the staging site, you just need to copy and paste it to your live site
By this token, a staging environment can help you avoid errors in operation beforehand and leave you enough room to check the whole website setup. If there is anything at fault, you have enough time to correct it accurately. Maybe now, you cannot wait to try your hand at creating a staging environment for your website and make a big difference for further development. Here, two methods are introduced to you.
Method 1: Create Staging Environment with WordPress Plugin
WordPress has released thousands of plugins to help users solve various problems. Fortunately, staging environment is taken into consideration as well. For some readers looking for an understandable method to settle this matter, we would like to set an example of how to create staging environment with Sandbox plugin.
The Sandbox plugin enables you to create a test website with few clicks and that is just a copy of your live site. In this case, the potential dangers are all throttled before coming into effect on the live site. What’s more, you are able to test anything as needed in terms of plugin updates, theme changes, setting changes and WordPress upgrades.
Log into your WordPress dashboard and take Sandbox plugin into effect once you have installed it via Plugins > Add New.
Since you have the plugin installed and activated successfully, a new item called “Sandbox” appears in the dashboard sidebar. Click this item and go to Sandbox interface. You are required to create your first sandbox as a staging site by clicking “Add New” button.
And then, give your new sandbox a shortname, name and description. “Create” this sandbox if you have filled out all information as required. Note that, it may take few seconds to create a sandbox for your live site.
When turning to the next page, you are able to check a list of information about the newly created sandbox. To check more details, the “Show Details” options can help you a lot. If everything goes correctly, you can click “Activate Text Site 1” to make your first sandbox into effect.
In this situation, the Sandbox plugin has generated a copy of the database tables, data and files on your website. Meanwhile, the copied web content has been included in a new set of area with a different prefix.
Since a notice reading “Currently in Test Site 1 sandbox…” appears on the dashboard, you are staying in a staging environment. That is just a clone of your live site! Note that, you are allowed to go back to your live site by clicking “here” included in the notice.
And now, you can make any changes on your test website. For instance, we are not satisfied with the current theme and wish to replace it to another premium one, thus, we go to Appearance > Themes and activate another theme. Go to the website frontend to check if the new theme works with your website properly. If so, you need to put this theme into effect on your live site by repeating the above-mentioned steps again.
In this way, you don’t have to take certain space on the live site to try different themes. The staging site gives you an opportunity to make a hit at the first time. Here, we list more plugins as below for you to create a staging environment with ease.
- Content Staging – As the name suggests, this plugin is used to create staging environment for posts, pages, images, and some other web content. That is to say, you are allowed to modify a post in a staging environment before publishing it on your live site.
- Staging Users Control – This is plugin is designed for webmasters who wish to lock all people out of the live site backend. You can appoint certain users to make some changes on your website in a staging environment, which takes no effect to the live environment.
- Stage WP Plugin Manager – You are allowed to determine which plugins can be automatically activated in three situations, including staging environment, production stage and local server.
In fact, Sandbox and the three recommended plugins are all used for creating staging environment but carry out their own duties. We hope that all those plugins can be a part of your success in further development.
Method 2: Create Staging Environment via cPanel
Since some people plan to create a staging environment manually rather than use a WordPress plugin, we would like to show you the second method that is creating staging environment via cPanel as below. To make sure that everything goes on wheels, we suggest you to go with a cPanel hosting company who provides you with the latest cPanel.
If everything is ready, you need to log into cPanel with your account. Before everything, you are required to create a subdomain for your staging site. Go to Domains > Subdomains and enter a subdomain as planned. For example, we plan to create a staging site for WhatsWP.com and set the subdomain as staging.whatswp.com. Note that, the document root is generated as /public_html/staging automatically. Finally, click “Create” button to create this domain.
And then, you are required to create a new FTP account for your staging site for ease of uploading files and data. Note that, this FTP account has nothing to do with your live site, and it only serves for the staging environment. Go back to cPanel interface and access to Files > FTP Accounts.
Enter the subdomain for your staging site in the Login field and set a strong password for your account. Besides, the Directory field should be filled in your document root generated in the previous steps. Finally, “Create FTP Account” to go to the next step.
And now, you have successfully created an independent FTP account for you staging site. Let’s get started to copy all web content from the live site and then upload those content to the staging environment. Here, we are going to make use of phpMyAdmin, which is a great tool for database management and can help you copy & paste all data from live site to staging environment easily. Go to cPanel > Databases > phpMyAdmin.
Since you have entered the phpMyAdmin interface, select the database being used from the left sidebar. And then, a list of tables included in Structure tab available for you. Move to the menu bar and pitch on Operations tab.
Here are four sections available for you, including “Create table”, “Rename database to”, “Copy database to” and “Collation”. Focus on the “Copy database to” mode and this is where to determine which content included in the live database should be copied to the staging site. Copy and paste the database name of staging environment in the blank and check the option “Structure and data”. Leave other default settings and click “Go” button.
And now, it’s time to modify the copied database via SQL tab. Select the database that you have created for the staging site just now and then add the following SQL queries to the blank. In this way, everything will go with a swing and you run the copied database smoothly.
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');
Note that, you have to replace the values of ORIGNIAL_URL, NEW_URL and wp_ to your original site URL, new URL and the prefix of database tables respectively. Finally, click “Go” button to make all SQL queries into effect.
Since now, you have copied all data of your live database to the staging environment, and then you need to set about copying other web content to the test site, including uploads, themes, plugins, etc. Besides, you can install the latest version of WordPress and upload it to the staging site. Here, we would like to fall back on FTP Manager. Go to cPanel > Files > File Manager.
Open the wp-content folder included in the root document, which shows you the web content that requires you to copy and paste to the test site. There are four folders available in the wp-content category, including plugins, themes, upgrades and uploads.
You need to right click each folder and “Copy” it in real time. Since a pop-up comes to you, you need to enter the directory root of the staging website. Click “Copy File(s)” to confirm all settings.
Once copying all content to the staging environment, you can visit staging site via the newly created subdomain. Make sure that the staging database has been connected to WordPress. If not, you are required to create a wp-config file for the staging site. Since all things get ready, you are able to log into the staging site backend with the same login information with your live site, and then make some changes in this staging environment. You can feel free to changes all settings on the test site, for which make no difference for the live site.
If you have all changes done and need to copy the staging site to your live site, you are required to copy all data from the staging database to the live database via cPanel > Databases > phpMyAdmin. And then, copy all web content to your live site via Files > File Manager.