
WordPress doesn’t have built-in support for developers working in multiple environments, i.e. local, staging, and production. It’s no surprise, given that this workflow isn’t part of the vast majority of users’ lives when publishing with WordPress.
Nevertheless, running a separate development site can be a complex and tedious endeavor and WordPress doesn’t make it very easy. The process usually involves updating the database settings in wp-config.php and running a SQL change on the database to update the ‘wp_siteurl’ and ‘wp_home’ settings. Developers have different tools to help streamline the task of moving between different environments, but it’s still a pain.
WordPress Multi-Environment Config
Simon Jones is the founder and technical director of Studio 24, a web development agency that works extensively with WordPress. He believes that the platform should have better support for those working in multiple environments and has created an extension to the WP config system to elegantly support this.
“In order to efficiently work on a project I prefer to have all the setup for different environments in the website code,” Jones said. “So when we push changes to staging things just work.” To that end, he created the WordPress Multi-Environment Config project. It supports using WordPress in local development, staging, and production environments without having to edit your config files or update the site URLS in your database.
Jones used an approach based on FocusLab’s work on the ExpressionEngine master config. It splits the config files out into:
- wp-config.default.php – any shared settings used across all environments
- wp-config.{environment}.php – the settings for a specific environment
- wp-config.env.php – sets up which URLs work for which environments
- wp-config.php – the original WP config file which now contains loading code
The way it works is that you copy any shared settings, i.e. auth keys and salts, into wp-config.default.php. You then copy your unique settings for each environment, i.e. database access details, to the wp-config{environment}.php file. In the wp-config.env.php file you then specify which URLs are defined for which environment. You can also set the environment via a webserver environment variable if you like.
Once all of this is in place, WordPress will load the default config settings first, followed by the correct environment config based on either the settings in wp-config.env.php or the webserver environment variable. Your configuration then works seamlessly across your local, staging, and production URLs.
Jones’ experience with agency work inspired him to create the WordPress multi-environment config project. “Like many web developers and digital agencies, at Studio 24 we work on multiple environments for client websites,” he said. “[pullquote]In my experience most CMSs don’t have great support for multiple environments[/pullquote], it’s usually a case of local config files or changes to the database when files are pushed live. Even Drupal is only just starting to look at adding support for multiple environments in Drupal 8.”
Jones believes that WordPress needs multiple environment support in core. “Very few CMSs really consider this and it’s an essential feature for people working on the modern web,” he said. “With all the great improvements in WordPress over the past few years, features to help developers deploy and work on multiple environments would be great to see.”
A better configuration management system would allow WordPress developers to be more efficient when working with enterprise environments, which often have more complex deployment workflows. Smaller agencies, individuals and anyone building WordPress sites may also benefit. Even if most WordPress users don’t work on their sites in multiple environments, there might be a way to make configuration management easier for those who do.
In the meantime, Jones’ WordPress Multiple Environment Config provides a nice solution. Although it doesn’t handle migration of database data between environments, this setup offers a clean and convenient way to manage configuration when moving between sites. For more details on how to install and use it, check out the project’s page on GitHub.
Sounds impressive Sarah
“Work Seamlessly Between Development, Staging, and Production Sites” is perhaps the “Philosopher’s stone” of WordPress.
I’ll have to read this one a couple of times to understand the details.