How to create staging environment?

How to create staging environment?

In the previous article we discussed why it is a good idea to have a staging environment. Now it is time to get our hands dirty and create actual environments. Before we start, let’s sum up the requirements for staging environment.

1. Production-like Environment

Make sure your staging environment uses the very same versions of all software in stack. That means the same version of operating system, database, PHP, server app etc. Every app behaves differently in other versions and even under another OS. Your WordPress, plugins and theme version should be the same on staging as on production. This will let you test and diagnose the production bugs precisely and debug them. 

Having the same caching rules and policy on all levels in both environments is important too. This can uncover for example problems with caching security wp nonces for forms or other caching-related issues.

2. Non-public Environment

Your staging environment is meant for internal purposes such as debugging, testing, showing changes to a client. You should avoid publishing your staging environment due to many reasons. One of them is duplicate content for Google, shooting your SEO-self in the foot. Best approach is to use Basic Auth username and password, which you can easily share inside your team or with your client, but it will create a non-penetrable membrane for bots and outer world.

Standard shared hosting

If you are on a budget and you use the “standard” hosting solution, creating a staging environment is a bit tricky, but not impossible. Many hosting providers allow you to create another site on the subdomain e.g. staging.example.com or as a subfolder example.com/staging. If there is no option in your dashboard to “create a new site”, you should follow these general steps:

  1. Investigate which type of install is allowed (subdomain vs. subfolder).
  2. Create a new (S)FTP user to access the root directory of your staging website. This usually is somethink like (ROOT/subdom/staging, ROOT/staging).
  3. Setup a new database user and a new database if possible. In the case when both production and staging sites share DB, you need to make sure that staging site uses the different $table_prefix.
  4. If you are using a subdomain install, point the subdomain to the IP of hosting server. Make sure to create SSL certificate for this subdomain inside hosting panel.
  5. Export database from your production site. In this step it is important to run a search-replace on all your tables to change URLs of production to the staging ones. Also change the prefixes of tables if applicable.
  6. Import database with changed URLs and prefixes.
  7. Copy files from your web root of production site.
  8. Edit wp-config.php to match all settings (new URL, database credentials, wp salts, table prefix etc.).
  9. Copy all the files to the root of staging site.
  10. Edit the .htaccess and .htpasswd to enable basic auth protection.
  11. Access your new staging site.

Since your new staging site is on the very same server as your production you won’t need any extra hacks about settings. Just make sure you have set the same memory and PHP timeout limits. Some hosting providers also allow to use other version of PHP/DB engine to be run on your staging site, which is great for testing before you upgrade your production site.

Professional Hosting or Managed Server

Many professional hosting providers or managed server providers allow you to easily create a staging environment out of a dashboard. Just search for “environments” or “staging/testing” inside your dashboard or consult with support. Staging environment is usually a part of your subscription fee so no extra charges should be applied.

Self-managed Server

Are you managing your server by yourself? Great! As a first improvement, you should start using configuration management tool such as Ansible or Puppet. Do it even if you manage just one server now. You will see how it makes your life easier

Here at Zeni we use Trellis, which is a collection of Ansible playbooks for WordPress projects. It already comes with preset environments for development, staging and production along with automated deployment and provisioning. You can have your environments automated just in hours


Do you need help with your staging environment or hosting solution? We provide professional hosting solutions with full automation of deployment and releases based on Ansible and Gitlab CI as well as consultations on how to make your projects easily managed. Reach us out via contact form and we will discuss with you the best option for your project.

Share on:

More articles:

Don’t miss anything!

Subscribe to the Newsletter to receive the most interesting tips about successful websites.

Seven reasons to use staging environment for your project on WordPress

Seven reasons to use staging environment for your project on WordPress

or seven ways to screw it without a staging.

0 What is Staging?

Staging or testing environment is a production-like environment where you can test new features in terms of integration testing and user acceptance testing. In other words, it is a 1:1 copy of your live site, where you can apply new things in the testing environment without screwing it up for your client and site visitors.

1 WordPress core updates

WordPress itself is under continuous development. Releases are divided into two groups: major and minor. Major releases (marked X.Y) are scheduled and you can beforehand read about what the new features will bring, whereas minor releases (marked X.Y.Z) are mostly about bug or security fixes and they come into usage more unexpectedly. Both types of releases can break something. There can be backwards compatibility of themes/plugins/your code, removing/upgrading of 3rd party libraries, or they can change Gutenberg blocks behavior etc. Are all plugins and theme you use ready for the new WP Core release? You can never make sure of this. In general, testing this on your live website is not the best idea.  Use staging!

2 Plugins and/or Themes updates

While WP Core major upgrades are pretty predictable and they have a solid schedule, this is rarely true with plugins and themes. This means that with a medium WP site (in terms of number of plugins), you will get a surprise upgrade at least once a week. Many paid plugins usually don’t have a transparent changelog, which makes predicting potential errors or clashes almost impossible. The only way to keep your live site stable is toalways upgrade on staging first”.

3 Place to test that awesome new plugin

Let’s implement that social media integration with this plugin! But sir, it seems like it made image uploads not working and last ten thousands of articles imported last night are missing featured images now. Another night fixing, great!. This would not have happened with testing this plugin on staging first.

Meme Production is down, another great night fixing

4 Place to test updates of a server stack

So your site is still running on PHP 5.6, right? Try PHP 7.4 and make it faster! So you upgraded PHP on your live site and now all you can see is a bunch of Fatal Error messages along with 2 hours of e-commerce site downtime in which your client lost a few thousand bucks. Good job, bro!Next time you will run that through staging first, promise?

5 Place to test your code

Will my code work well with code of other team members? Don’t forget, your “team” is not just inside your company, but also includes all developers who contributed to any part of the website (WP Core, plugins…).  You should always test your code locally before pushing it to any other environment, but you usually need the client, project manager and QA team to take a look. Or do you need to perform testing on real people? Perfect, here you got staging to make your life easier.

6 Experiment with CMS

“What if we move that widget from left panel to the footer and change its’ title?” Any bigger change in CMS should be first tested on staging. From experience, clients can quickly change their mind when they see their brilliant idea alive on the site. Are you using any kind of page builder for your frontend? Previews are powerful feature, but usually you need to see the whole picture including menus, plugin setting changes and so on. That’s where staging comes in very handy. Also you don’t want visitors to see that jumping widgets and menu items on production, do you?

7 Showroom for your Client

Bringing your laptop to the client’s office nowadays (considering both global market and pandemic) isn’t the best idea of showing your client that awesome new feature. Ever heard of wow-effect? Don’t do that, please. Show your client new features incrementally on your staging. You both will sleep much better, trust me!

Meme We found more bugs than our customers did

In the next article we will take a look on how to set up a staging environment.

If you are interested in your own quality website and need help, write to us and we will be happy to help you.

Share on:

More articles:

Don’t miss anything!

Subscribe to the Newsletter to receive the most interesting tips about successful websites.