Local Community


Issue Summary

If other plugins define the constant WP_ENVIRONMENT_TYPE then a PHP warning is displayed as the constant is already defined.

I develop plugins that allow the user to change this setting and having this define in the local-bootstrap.php file of each new application release causes issues.

There really is no development reason to add the WP_ENVIRONMENT_TYPE to the bootstrap file. If you’re looking for a place to put it, it should belong in the site’s wp-config.php file. At least when it’s here it can be correctly overriden in a safe simple manner.

Pretty please.

What kind of plugins are defining that constant? Surely something proprietary, right?

Sort of proprietary. Local implemented this using the auto-prepend-file feature in PHP:

@Jacob: Local is using the PHP.ini auto_prepend_file setting to prepend a PHP file that sets the WP_ENVIRONMENT_TYPE constant.
Local does scan a site’s php.ini in case you are manually adding that setting. If a site is manually adding something in this way, then it’s important to note that Local won’t be able to automatically prepend this constant, and so certain things won’t work as intended.


There’s been some great feedback around this implementation, with one of the main pain points being Xdebug’s step-debugger:

@sternerstuff I have developed the Local Development plugin which allows the user to set this constant within the wp-config.php file.

Having the constant defined in a location that is not able to be overwritten causes errors.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

I just wanted to add that this setting now breaks Bedrock-based projects as they recently added support for configuring WP_ENVIRONMENT_TYPE, which throws a fatal error due to this value being preset by Local.

I’m now faced with either having to implement an external solution as offered by @afragen across multiple projects, or directing the team to modify their local-bootstrap.php file (and repeat after every Local update), neither of which is a desirable option.

I’d like to repeat the request to please relocate this to wp-config.php

1 Like

Hi @genyus

Thank you for following up and sharing your insight! I checked with the Local Devs and this is indeed something they are still aware of and looking into. We don’t have any kind of ETA to provide at this time but I wanted to at least let you know it wasn’t forgotten and any updates will be shared in the forums here.


Hey all! Just chiming in here - the engineering team meets once a week to discuss plans for upcoming work, and we’re going to talk through this issue tomorrow.

There are probably phases to this -

  1. Just move the WP_ENVIRONMENT_TYPE to the wp-config file
  2. Add some sort of UI to control this at a site-by-site level
  3. Add some sort of UI to set this at an app level to apply to all sites

The first phase is straightforward and what we’ll talk about in the morning. The only caveat is that this would be for all NEW sites in Local… we’ll have to talk about if a backwards compatible option exists that avoids a null environment variable for older sites. Hopefully this will be in a Local release very soon!

1 Like

Today I tried to use Local with Bedrock and I found your comment because I faced the exact issue you mention. Is there an easy way to work around this? So far this is the only project with Bedrock so I don’t need something really fancy for all my local sites.

Fatal error: Uncaught Roots\WPConfig\Exceptions\ConstantAlreadyDefinedException: Aborted trying to redefine constant 'WP_ENVIRONMENT_TYPE'. define(‘WP_ENVIRONMENT_TYPE’, …) has already been occurred elsewhere. in C:\Users\jenniferm\Local Sites\bedrock\app\bedrock\vendor\roots\wp-config\src\Config.php:106 Stack trace: #0 C:\Users\jenniferm\Local Sites\bedrock\app\bedrock\vendor\roots\wp-config\src\Config.php(26): Roots\WPConfig\Config::defined('WP_ENVIRONMENT_...') #1 C:\Users\jenniferm\Local Sites\bedrock\app\bedrock\config\application.php(57): Roots\WPConfig\Config::define('WP_ENVIRONMENT_...', 'development') #2 C:\Users\jenniferm\Local Sites\bedrock\app\bedrock\web\wp-config.php(8): require_once('C:\\Users\\jennif...') #3 C:\Users\jenniferm\Local Sites\bedrock\app\bedrock\web\wp\wp-load.php(55): require_once('C:\\Users\\jennif...') #4 C:\Users\jenniferm\Local Sites\bedrock\app\bedrock\web\wp\wp-admin\admin.php(34): require_once('C:\\Users\\jennif...') #5 C:\Users\jenniferm\Local Sites\bedrock\app\bedrock\web\wp\wp-admin\index.php(10): require_once('C:\\Users\\jennif...') #6 {main} thrown in C:\Users\jenniferm\Local Sites\bedrock\app\bedrock\vendor\roots\wp-config\src\Config.php on line 106


Same thing here… trying to build WP based on Bedrock and
Roots\WPConfig\Exceptions\ConstantAlreadyDefinedException: Aborted trying to redefine constant ‘WP_ENVIRONMENT_TYPE’. define('WP_ENVIRONMENT_TYPE', ...) has already been occurred elsewhere. in /Volumes/data/…/devel/app/public/bedrock/vendor/roots/wp-config/src/Config.php on line 106

Indeed modifing bedrock Core is not desired at all.
The “WP_ENVIRONMENT_TYPE” should be an extra value people like us can turn in the Localwp off.

1 Like

For now, we’ve taken the approach of modifying the local-bootstrap.php file:

The modification will need to be repeated every time Local is updated, but we created a simple bash script to make it as easy as possible when that becomes necessary.

1 Like

Just found a much better solution. Looking again at the Bedrock code, I realised that it only tries to define the WP_ENVIRONMENT_TYPE constant if the WP_ENVIRONMENT_TYPE environment variable isn’t set. Simply add WP_ENVIRONMENT_TYPE='local' to your .env file and that will get everything working again without any other modifications necessary.


Hello all!

I just thought I’d jump in here to share this since there seem to be several Bedrock users here. We also have a feature request active you can view at the link below to track interest in further support for Bedrock in Local. Feel free to upvote, comment, and follow along for updates.


Hey @genyus you are actually a genius! This fix totally worked on my bedrook/local environment.

AMAZING! Thank you so much…

1 Like