Skip to content

Manage environment variables for a VIP Local Development Environment

Managing environment values with the VIP-CLI vip config envvar command is for VIP Platform environments only, and cannot be used on a VIP Local Development Environment. Manage environment variables on a VIP Local Development Environment by manually adding them as a defined constant instead.

Limitations

This method will only work for the VIP Local Development Environment as expected if:

Define an environment variable

Though definitions for constants can be added to any file loaded by WordPress, it is strongly recommended to create a file in the client-mu-plugins directory that is dedicated to defining constants for the local environment.

After creating the file, add it to .gitignore (e.g., client-mu-plugins/*.local.php) to avoid committing sensitive values to source control.

In this example, a file named client-mu-plugins/vip-env-vars.local.php has been created and a definition for the environment variable MY_CUSTOM_VAR is added:

client-mu-plugins/vip-env-vars.local.php
<?php
/**
 * Local environment variables
 */

define( 'VIP_ENV_VAR_MY_CUSTOM_VAR', 'my custom value' );

Once defined, the same methods for accessing environment variables in a VIP Platform environment can be used on the local environment:

$my_value = vip_get_env_var( 'MY_CUSTOM_VAR', $default_value );

Last updated: April 04, 2024

Relevant to

  • WordPress