Using environment variables

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 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 environments.

Additional environment variables are available for Pipelines.


Applications on Cloud Platform have a special include statement in the settings.php file like the following example:

if (file_exists('/var/www/site-php')) {
   require '/var/www/site-php/sitename/';

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 in the Cloud Platform interface, or by storing private information in the file system.


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_SITE_GROUP string Specifies the site name, which is also the Unix user.  
AH_SITE_ENVIRONMENT string Indicates a Cloud Platform environment. dev, test, prod, ide
AH_PRODUCTION string Indicates whether this environment is a Production environment. 1 for Production, undefined for non-Production
AH_NON_PRODUCTION string 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 in which the web infrastructure processing the current request is running.  
AH_REALM string The realm in which the application is running.  
AH_SITE_NAME string Specifies the environment name.  
HTTP_X_REQUEST_ID string Every web request received by Cloud Platform is assigned a unique request ID, which is set in the HTTP header X-Request-ID and is available in the HTTP_X_REQUEST_ID environment variable; for more information, see Using HTTP request IDs.  
PATH string 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 at /mnt/tmp/[site].[env] for the environment. Use this variable, rather than /tmp, which 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 use instead of

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
// 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.

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:


For an example of this technique’s use, see Overriding Solr index connection switching.


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
     case 'test':
       // do something on staging
     case 'prod':
       // do something on prod
       // Site Factory may require a different value depending
       // on site configuration
     case 'ra':
       // do something on ra - necessary if a
       // Remote Administration environment is present
    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'])     {
   $conf['apachesolr_read_only'] = "1";

For another example, see Setting base URLs.