Manage environment variables
Environment variables are a method for injecting information into WordPress and Node.js WPVIP 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 adevelop
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.
- Environment variables on a VIP Platform environment can only be managed with VIP-CLI, using the subcommands of
vip config envvar
. - On a VIP Local Development Environment, environment variables can only be managed by manually adding them as a defined constant.
- 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.
- New or updated environment variables will not be available until the application’s next code deployment.
Reserved names
Some environment variable names are reserved:
- The prefixes
WPCOM_
,VIP_
, andIS_VIP_
are reserved and cannot be used for environment variable naming. - To avoid conflicts, names reserved for WordPress constants (e.g.
DB_NAME
) cannot be used as environment variables.
Manage environment variables with VIP-CLI
Prerequisites
- VIP-CLI is installed and has been updated to the most current version.
- Only users with an Org admin role or an App admin 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) with the subcommands of the VIP-CLI command: vip config envvar
.
Add or update a value
Caution
New or updated environment variables will not be available until the application’s next code deployment.
Use the VIP-CLI command vip config envvar set [options]
to add or update an environment variable and assign it a value.
In this example, the new environment variable EXAMPLE_ENV_VAR
is added:
vip @example-app.develop config envvar set EXAMPLE_ENV_VAR
At the next prompt in the command line, the user enters the value 1234567890
:
For multiline input, use the --from-file option. ✔ Enter the value for EXAMPLE_ENV_VAR: · 1234567890
The user is prompted to confirm that the entered value is correct before it is assigned to the EXAMPLE_ENV_VAR
variable:
✔ Please confirm the input value above (y/N) · true
Successfully added environment variables and values will return an output message similar to this:
Successfully set environment variable "EXAMPLE_ENV_VAR"
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 and are accessed using process.env
. For example:
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:
<?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: April 11, 2025