---
title: "Creating custom environment variables"
date: "2024-02-14T06:18:38+00:00"
summary: "Create and manage custom environment variables in Cloud Platform to enhance your Drupal application's flexibility. Set, edit, and remove variables securely through the user interface or API for seamless development workflows."
image:
type: "page"
url: "/acquia-cloud-platform/creating-custom-environment-variables"
id: "7bbbeaff-84f0-4a99-b67c-63f92850c8ae"
---

Table of contents will be added

This document contains information about creating custom environment variables in the Cloud Platform user interface.

Important

This feature is unavailable in Site Factory. See [Setting Site Variables on website](https://docs.acquia.com/site-factory/manage/settin-site-variable) instead for a similar feature in Site Factory.

In addition to the [environment variables provided by Cloud Platform](/acquia-cloud-platform/develop-apps/env-variable), you can also create custom environment variables for your application using the Cloud Platform user interface or [using the Cloud Platform API](#cloud-api-variables). 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 Cloud Platform user interface enables you to add, edit, and delete custom environment variables quickly and easily. Since working with custom variables is restricted by [permissions](/acquia-cloud-platform/access/teams/permissions), the Cloud Platform interface contains the appropriate items for working with variables only if you have adequate permissions.

![cloud-platform_environment-variables.png](https://acquia.widen.net/content/e95334a7-0768-4da5-84eb-05429fa2f8ca/web/cloud-platform_environment-variables.png)

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.

While creating custom variables in Cloud Platform, ensure that you:

*   Limit each variable value to a maximum of 5000 bytes.
*   Limit each variable name to a maximum of 255 bytes.
*   Limit the total size at 100 kilobytes, including all variables with their names and values.
*   Do not include tabs, spaces, or quotation marks in variable names and values.
*   Do not start variable names with "AH" or "ACQUIA".

Note

*   After changing a custom environment variable, you must start a new SSH session to see the updates to those variables.
*   In Cloud Next, modifying custom environment variables initiates the provisioning of new Drupal pods.
*   Additional environment variables are available for [Pipelines](/acquia-cloud-platform/features/pipelines/variables).

Security considerations for custom variables
--------------------------------------------

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 logs](/acquia-cloud-platform/monitor-apps/logs/drupal-watchdog). Acquia recommends you do not include sensitive items, like the following examples, in a custom variable:

*   SSL certificates
*   SSH keys
*   Login credentials
*   API credentials

Adding a custom variable
------------------------

To add a custom environment variable:

1.  [Sign in to the Cloud Platform user interface](/node/55875), and select your application.
2.  Select the environment to which you want to add a variable.
3.  In the left menu, select **Variables** > **Add Environment Variable**.
    
    ![cloud-platform_adding-environment-variables.png](https://acquia.widen.net/content/2df0f14d-1254-425c-ac93-98e2caa82570/web/cloud-platform_adding-environment-variables.png)
    
4.  Add the information for your variable:
    *   **Name** - Example: `Drupal_API_URL`
    *   **Value** - Example: `http://mydrupalsite.com/api`
5.  Click **Add** to add the variable, or click **Cancel** to discard your changes.

After your environment restarts, an item appears in the [task log](/acquia-cloud-platform/monitor-apps/tasks) and the new variable is included in the **Environment Variables** list.

Editing a custom variable
-------------------------

To update an existing custom variable:

1.  [Sign in to the Cloud Platform user interface](/node/55875), and select your application.
2.  In the left menu, click **Variables**.
3.  Find the variable that you want to change, and click **Edit**.
4.  Replace the information in the **Value** text box with your updated data.
5.  Click **Update**.

After your environment restarts, an item appears in the [task log](/acquia-cloud-platform/monitor-apps/tasks) and the variable’s new value is displayed in the **Environment Variables** list.

Calling a custom variable
-------------------------

Custom environment variables are available in both the `$_ENV` and `$_SERVER` [superglobals](https://www.php.net/manual/en/language.variables.superglobals.php). 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');

Removing a custom variable
--------------------------

To remove a custom environment variable from use:

1.  [Sign in to the Cloud Platform user interface](/node/55875), and select your application.
2.  In the left menu, click **Variables**.
3.  Find the variable that you want to delete, and click **Remove**.
4.  Click **Update**.

After your environment restarts, an item appears in the [task log](/acquia-cloud-platform/monitor-apps/tasks) and Cloud Platform removes the variable from the **Environment Variables** list.

Filtering for specific variables
--------------------------------

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.

Custom variables in the Cloud Platform API
------------------------------------------

The [Cloud Platform API](/acquia-cloud-platform/develop-apps/api) provides the following endpoints for working with custom environment variables:

Function

Endpoint

Return a list of environment variables

[GET /environments/{environmentId}/variables](https://cloudapi-docs.acquia.com/#/Environments/getEnvironmentsVariables)

Add a new environment variable

[POST /environments/{environmentId}/variables](https://cloudapi-docs.acquia.com/#/Environments/postEnvironmentsVariables)

Retrieve an environment variable

[GET /environments/{environmentId}/variables/{environmentVariableName}](https://cloudapi-docs.acquia.com/#/Environments/getEnvironmentsVariable)

Delete an environment variable

[DELETE /environments/{environmentId}/variables/{environmentVariableName}](https://cloudapi-docs.acquia.com/#/Environments/deleteEnvironmentsVariable)

Update an existing environment variable

[PUT /environments/{environmentId}/variables/{environmentVariableName}](https://cloudapi-docs.acquia.com/#/Environments/putEnvironmentsVariable)