In addition to the environment variables provided by Acquia Cloud, you can also create custom environment variables for your application using the Acquia Cloud interface or using the Acquia Cloud API. These custom environment variables are set globally (on a per-application basis) and can be used to define anything your application may need to work with, including Drupal APIs and environments.
The Acquia Cloud interface enables you to add, edit, and delete custom environment variables quickly and easily. Since working with custom variables is restricted by permissions, the Acquia Cloud interface contains the appropriate items for working with variables only if you have adequate permissions.
By default, the value of the custom variable is hidden for security. Click Show to display the value, or Hide to hide it from view again.
Note
Custom environment variables aren’t encrypted, and aren’t a substitute for secure credentials. Custom environment variables can be exposed in your application’s Drupal watchdog log. Acquia recommends you do not include sensitive items, like the following examples, in a custom variable:
Using the Acquia Cloud interface, complete the following steps to add a custom environment variable:
Sign in to Acquia Cloud, and then select your application.
Select the environment to which you want to add a variable.
In the left menu, click Variables, and then click Add Environment Variable.
Add the information for your variable:
Drupal_API_URL
http://mydrupalsite.com/api
Click Add to add the variable, or click Cancel to discard your changes.
After your environment restarts, an item will appear in the task log and the new variable will be included in the Environment Variables list.
If you have a problem or need to update an existing custom variable, you can edit them from the Variables page, using the following procedure:
After your environment restarts, an item will appear in the task log and the variable’s new value will be displayed in the Environment Variables list.
Custom environment variables are available in both the $_ENV
and
$_SERVER
superglobals. To call
a custom variable, add the following code to your settings.php
file,
modifying variable_name
to meet your application’s needs:
$myVariable = $_ENV['variable_name'] ?? getenv('variable_name');
To remove a custom environment variable from use, complete the following steps:
After your environment restarts, an item will appear in the task log and Acquia Cloud will remove the variable from the Environment Variables list.
If you need to locate a specific custom environment variable, use the Filter Variables field in the upper-right corner of the webpage to filter your displayed variables based on your entered text.
The Acquia Cloud API provides endpoints for working with custom environment variables, including the following:
Function | Endpoint |
---|---|
Return a list of environment variables | GET /environments/{environmentId}/variables |
Add a new environment variable | POST /environments/{environmentId}/variables |
Retrieve an environment variable | GET /environments/{environmentId}/variables/{environmentVariableName} |
Delete an environment variable | DELETE /environments/{environmentId}/variables/{environmentVariableName} |
Update an existing environment variable | PUT /environments/{environmentId}/variables/{environmentVariableName} |