---
title: "Using environment variables"
date: "2024-02-14T06:18:38+00:00"
summary: "Learn how to use Cloud Platform environment variables in your app code and Drush commands for environment-specific functionality."
image:
type: "page"
url: "/acquia-cloud-platform/using-environment-variables"
id: "36c26b35-09a6-4204-b1d9-5b5daa8f2579"
---

Table of contents will be added

This document contains information about using Cloud Platform environment variables in your application.

Cloud Platform makes environment variables available for your use in both your application code and [Drush](https://www.drupal.org/project/drush) commands. With these variables, you can write code that responds to the environment in which it runs. For example, you may want to run certain commands only in your production environment, but not in the development or staging environment.

Additional environment variables are available for [Pipelines](/acquia-cloud-platform/features/pipelines/variables).

Important

Applications on Cloud Platform have a special [include statement](/acquia-cloud-platform/manage-apps/code/require-line) in the `settings.php` file like the following example:

    if (file_exists('/var/www/site-php')) {
       require '/var/www/site-php/sitename/sitename-settings.inc';
      }
    

If you use environment variables in `settings.php`, you must place references to the environment variables _after_ the preceding include statement, to ensure they take effect in only the desired contexts.

In addition to the environment variables provided by Cloud Platform, you can provide information to your application by creating [custom environment variables](/acquia-cloud-platform/manage-apps/variables) in the Cloud Platform interface, or by [storing private information in the file system](/acquia-cloud-platform/manage-apps/files/system-files/private).

Note

After changing a custom environment variable, you must start a new SSH session to see the updates to those variables.

Available environment variables
-------------------------------

Cloud Platform includes the following environment variables:

Variable

Format

Description

Values

`AH_ENVIRONMENT_TYPE`

string

The type of the Cloud Platform environment. This variable is available only for Multi-Experience Operations environment.

`meo`

`AH_DRUPAL_SITE_NAME`

string

The Drupal site machine name. This variable is available only for multi-experience operations environments.

 

`AH_SITE_GROUP`

string

The site name or the Unix user.

 

`AH_SITE_ENVIRONMENT`

string

The environment name.

*   `dev`
*   `test`
*   `prod`
*   `ide`

`AH_PRODUCTION`

string

The variable that indicates whether this environment is a production environment.

*   `1` for production
*   `undefined` for non-production

`AH_NON_PRODUCTION`

string

The variable that indicates whether this environment is a non-production environment.

*   `1` for non-production
*   `undefined` for production

`AH_CURRENT_REGION`

string

The [Amazon Web Services region](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html) where the web infrastructure processing the current request is running.

 

`AH_REALM`

string

The [realm](/definitions/realm) where the application is running.

 

`AH_SITE_NAME`

string

The site name or Unix user concatenated with the environment name.

 

`HTTP_X_REQUEST_ID`

string

The unique request ID assigned to every web request received by Cloud Platform. This is set in the HTTP header `X-Request-ID`. For more information, see [Using HTTP request IDs](/acquia-cloud-platform/develop-apps/drupal-apps/requestid).

 

`MAGICK_MEMORY_LIMIT`

string

The memory limit for [ImageMagick](https://www.drupal.org/project/imagemagick).

 

`PATH`

string

The location of all the executable for the environment. If you configure an environment to use a specific version of PHP, that version of PHP is first in the path.

 

`TEMP`

string

The [temporary directory](/acquia-cloud-platform/manage-apps/files/temporary) for the environment. This directory is located at `/mnt/tmp/[site].[env]`. Use this variable instead of `/tmp` because `/tmp` is smaller and may fill up rapidly.

 

Site Factory subscriber notes

Several examples from the preceding table require the following modifications to work with Site Factory:

*   The `AH_SITE_ENVIRONMENT` variable includes Site Factory-specific values for each environment, such as `01live` or `01test`.
*   [Default domain names](/site-factory/manage/domains#acsf-default-domain) use `acsitefactory.com` instead of `acquia-sites.com`.

Environment variables in `.htaccess`
------------------------------------

You can also use environment variables in your `.htaccess` file. In the following example, we redirect HTTP requests to HTTPS only on the production environment, and not in the development or staging environments:

    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{ENV:AH_SITE_ENVIRONMENT} prod
    // Site Factory may require a different value for
    // %{ENV:AH_SITE_ENVIRONMENT} depending on site configuration
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

For more information, see [Excluding Acquia domains and non-production environments](/acquia-cloud-platform/manage-apps/htaccess#redirect-exclude-acquia-domains).

Faking your environment variables for local testing
---------------------------------------------------

During testing, you may want to force a Cloud Platform environment variable to contain a specific value by making a change to your local `settings.php` file. The following example sets the `AH_SITE_ENVIRONMENT` variable to the `dev` environment:

    $_ENV['AH_SITE_ENVIRONMENT'] = 'dev';

For an example of this technique’s use, see [Overriding Solr index connection switching](/acquia-cloud-platform/features/acquia-search/managing/multiple-cores/override).

Examples
--------

For example, the following statement would let you switch code based on the environment:

    if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
       switch ($_ENV['AH_SITE_ENVIRONMENT']) {
         case 'dev':
           // do something on dev
           break;
         case 'test':
           // do something on staging
           break;
         case 'prod':
           // do something on prod
           // Site Factory may require a different value depending
           // on site configuration
           break;
         case 'ra':
           // do something on ra - necessary if a
           // Remote Administration environment is present
           break;
         }
        }
        else {
        // do something for a non-Acquia-hosted application
        // (like a local dev install).
    ; }

To make Acquia Search read-only on your Development and Staging environments, so the search index doesn’t have duplicate copies of content:

    // place this after the Acquia require line
    if (!isset($_ENV['AH_SITE_ENVIRONMENT'])  ||
      'prod' != $_ENV['AH_SITE_ENVIRONMENT'])     {
      $settings['acquia_search']['read_only'] = TRUE;
    }

For another example, see [Setting base URLs](/acquia-cloud-platform/develop-apps/drupal-apps/baseurl).