Title: Manage environment variables
Author: WordPress VIP Documentation
Published: October 27, 2021
Last modified: January 7, 2026

---

 1. [Infrastructure](https://docs.wpvip.com/infrastructure/)
 2. [VIP Platform environments](https://docs.wpvip.com/infrastructure/environments/)
 3. Manage environment variables

#  Manage environment variables

Environment variables are a method for injecting information into WordPress and 
Node.js VIP Platform environments.

Environment variables are commonly used to:

 * Provide sensitive values (such as API secrets) to an application without committing
   the values to a site’s GitHub repository or storing the values in a site’s database.
 * Provide flags that can be used to vary behavior between environments. For example,
   an environment variable can be set to provide one value to a `production` environment
   and a different value to a `develop` environment.

## Limitations

 * Each VIP Platform environment has its own discrete set of environment variables.
   For an environment variable to be available on all environments, it must be set
   on each environment separately.
 * An environment variable’s key is limited to 255 bytes.
 * An environment variable’s value is limited to 4096 bytes.
 * The overall limit of all keys and values of an environment’s environment variables
   is 16384 bytes.

## Reserved names

Some environment variable names are reserved:

 * The prefixes `WPCOM_`, `VIP_`, and `IS_VIP_` are reserved and cannot be used 
   for environment variable naming.
 * To avoid conflicts, names [reserved for WordPress constants](https://wordpress.org/support/article/editing-wp-config-php/)(
   e.g. `DB_NAME`) cannot be used as environment variables.

## Manage environment variables with VIP-CLI

**Prerequisites**

 * [VIP-CLI is installed](https://docs.wpvip.com/vip-cli/installing-vip-cli/) and
   has been updated to [the most current version](https://www.npmjs.com/package/@automattic/vip/v/latest).
 * Only users with an [Org admin role](https://docs.wpvip.com/manage-user-access/vip-dashboard/org-roles)
   or an [App admin role](https://docs.wpvip.com/app-role/) for that application
   can edit environment variables. Users with lower capabilities will only have 
   the ability to `list` the names of existing environment variables.

Manage environment variables (i.e. set, get, delete, or list) on a [**VIP Platform environment**](https://docs.wpvip.com/infrastructure/environments/)
with the subcommands of the VIP-CLI command: `[vip config envvar](https://docs.wpvip.com/vip-cli/commands/config/envvar/)`.

On a [**VIP Local Development Environment**](https://docs.wpvip.com/vip-local-development-environment/),
manage environment variables with the subcommands of `[vip dev-env envvar](https://docs.wpvip.com/vip-cli/commands/dev-env/envvar/)`.

### Add or update a value

Use the VIP-CLI command `[vip config envvar set [options]](https://docs.wpvip.com/vip-cli/commands/config/envvar/set/)`
to add or update an environment variable and assign it a value.

In this example command and output, a new environment variable `EXAMPLE_ENV_VAR`
is added to a WordPress environment. A value is assigned to the new environment 
variable and the user chooses to apply the environment variable immediately so that
it is available to application code:

    ```lang-shell
    $ vip @example-app.develop config envvar set EXAMPLE_ENV_VAR 
    For multiline input, use the --from-file option.

    ✔ Enter the value for EXAMPLE_ENV_VAR: · 1234567890
    ✔ Please confirm the input value above (y/N) · true
    ? Apply this environment variable update now? (y/N) › false
    Successfully set environment variable "EXAMPLE_ENV_VAR"
    Environment variable is active and available.
    ```

If the user chooses not to make the new or updated environment variable immediately
available, it will become available by default when the next code deployment occurs
on that environment.

**Caution**

By default, all new or updated environment variables on Node.js environments that
involve build-time changes will not be available until the next code deployment 
is made to that environment.

## Access environment variables in an application

Environment variables are always provided as strings, even if their value resembles
another data type (e.g., `"true"`, `"123"`, `"[1, 2, 3]"`). String values can be
converted or deserialized by an application into the desired data type, but they
should be validated thoroughly.

On the VIP Platform, environment variables are accessed differently depending on
the application type.

### Node.js

Environment variables are provided as actual [environment variables](https://nodejs.org/en/learn/command-line/how-to-read-environment-variables-from-nodejs)
and are accessed using `process.env`. For example:

    ```lang-js
    const apiKey = process.env.EXAMPLE_ENV_VAR || null;
    ```

### WordPress

**Note**

Both the the `Environment::get_var()` helper method and the `vip_get_env_var` helper
function are available for use throughout the application, even as early as in `
vip-config.php`.

Environment variables are accessed using the `Environment::get_var()` helper method
or `vip_get_env_var` helper function. For example:

    ```lang-php
    <?php
    // Using class method
    $api_key = Automattic\VIP\Environment::get_var( 'EXAMPLE_ENV_VAR', $default_value );
    // Using helper function
    $api_key = vip_get_env_var( 'EXAMPLE_ENV_VAR', $default_value );
    ```

Last updated: January 07, 2026