How to setup Multi-Environments in WordPress

In this post, I would like to show you how to configure multiple environments in WordPress. By using this technique you can deploy your WordPress application to development, staging, and production environments without having to edit your config files or update the site URLs in your database. The system detects what environment the current website is in and loads the relevant config file for that environment.

How to setup

You can achieve this in many ways, I will show you elegant and easily extensible version here.

First, you need to create environment specific config files in your root or any were in your server.We need to load this files based on the environment.

For example lets assume 3 environment called development, testing, production

Config files Ex: config-{environment}.php

  • Development: config-development.php
  • Testing: config-testing.php
  • Production: config-production.php

URLs may like this

  • Development: http://localhost
  • Testing: http://testing.website.com
  • Production: http://website.com

Edit $environments accordingly so they match your environments and their corresponding hostnames.

Then create a wp-config directory in the root of your project and create the following files inside:

Edit $environments accordingly so they match your environments and their corresponding hostnames.

Then create a wp-config directory in the root of your project and create the following files inside – wp-db-development.php, wp-db-testing.php, wp-db-production.php

Edit and add the following lines to each of your wp-db-*.php files:

For wp-db-production.php turn debugging off by defining WP_DEBUG to false

define('WP_DEBUG', false);

Benefits / Advantages

1. No need to edit Database configuration values.

2. you can maintain different/unique authentication keys and salts for each environment.

3. New environments can be added easily.

4. No need to change Error reporting settings manually. It should be turned on on development servers and off on staging and production.

5. we can block robots for development, staging environments.(duplicate content will hurt your clients SEO).

6. It will reduce the deployment time.

That’s it.

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments