Read time: 3 minutes
Last edited: May 29, 2020
This topic explains what environments are in LaunchDarkly and how to use them to manage different business areas or areas of your product lifecycle.
Environments are organizational units contained within projects. Environments allow you to manage your feature flags throughout your entire development lifecycle, from local development through production. Typical environments within a project could be Production, QA, Staging, or individual environments.
Your LaunchDarkly account supports an unlimited number of projects, environments, flags, and server-side Monthly Active Users (MAU). If you are on a legacy Starter plan, your account may be limited to two projects and two environments. Contact our Support team at firstname.lastname@example.org to remove those restrictions.
You can create multiple environments within each project, and all projects must have at least one environment. To learn more about projects, read [Projects]/home/managing-flags/projects.
Your first project has two environments,
Production, by default. Each environment has its own SDK key, which is used to connect the LaunchDarkly SDK to a specific environment.
Each feature flag that you create has its own set of targeting rules for each environment. This means that you can change your flag rollout rules in a development or staging environment for QA testing before rolling out to production.
The LaunchDarkly sidebar has a dropdown widget that shows you the current project and environment and allows you to quickly switch between projects and environments.
You can manage your environments from the Account settings page. Here, you can add new environments to a project (for example, to give each developer on your team their own environment for local testing).
To add a new environment:
- Navigate to the Account Settings page.
- Click New Environment. The "Create an environment" screen appears.
- Give your environment a human-readable Name.
- (Optional) Give your environment a unique Key. This field populates automatically based on your name, but you can change it now if you wish.
- (Optional) Add Tags.
- (Optional) Select the Enable secure mode checkbox to ensure a user of the client-side SDK cannot impersonate another user.
- (Optional) Select the Require comments for flag and segment changes checkbox to force members who modify flags and user segments to leave a comment to explain their changes.
When Require comments is enabled, the LaunchDarkly Dashboard will force members to explain their changes. Comments are not required for changes made with the LaunchDarkly API.
- (Optional) Select the Require confirmation for flag and segment changes checkbox to force members who modify flags and user segments to verify they wish to make these changes.
- (Optional) Select the Send detailed events to data export destinations checkbox to enable data export for every flag created in this environment after this checkbox is selected. To learn more, read Data Export.
- (Optional) Specify a TTL between 0 and 60 minutes. TTL, or Time to Live, is a setting in DNS records that dictates how long the record should be cached by nameservers and browsers.
The TTL setting checkbox only applies to environments using the PHP SDK. To learn more, read TTL settings.
- Choose a Color to differentiate this environment from other environments.
- Click Save Environment. The new environment appears on the Account Settings page.
You can migrate some, but not all, content between environments. Compare and copy flag settings between environments from the LaunchDarkly UI. To learn more, read Compare and copy flag settings.
Alternatively, use the REST API to migrate flags from one environment to another. First, GET the feature flag you wish to import, then PATCH to update the flag configuration in production.
If you need to reset an SDK key for an environment, navigate to the Account Settings page and click Edit next to the environment you wish to change.
When editing your environment, you'll see the option to reset your SDK key for that environment. Clicking the "Reset SDK Key" button will bring up a confirmation screen. From there you have the option to keep the old SDK key active for a period of time.
Each environment also has a time-to-live (TTL) setting. This sets the number of minutes that the PHP SDK can cache feature flag rules locally.
The TTL is only used in our PHP SDK, since PHP's shared-nothing architecture makes our streaming model impossible.
For customers using PHP, we recommend setting your TTL to at least 5 minutes in production environments. This lets our SDKs cache feature flag rules for 5 minutes, so most calls to
variation will not make a remote request. The tradeoff is that changes you make to your feature flag rules on your dashboard will not take effect for 5 minutes.
If your site has relatively low traffic (fewer than one request per minute), you may wish to increase the TTL to 5 minutes or more to take better advantage of the local cache.
If the TTL is set to 0 minutes, the SDK will not use a local cache, and every call to
variation will make a remote request to our CDN. You can set your TTL to 0 in testing environments to see changes reflected immediately, but we do not recommend a 0 minute TTL in production.
In high volume PHP environments, we strongly recommend using our Relay Proxy. To learn more, read The LaunchDarkly Relay Proxy.