# Drupal and the putenv() problem

> Drupal runs fine without the putenv() function, as long as environment variables are set in another way (e.g. in settings.php).

Source: https://www.hukot.net/community/en/tutorials/drupal-and-the-putenv-problem
Updated: 2026-11-25

#### Why is the `putenv()` function disabled?

The `putenv()` function changes the environment of the PHP process, which can be abused to bypass security restrictions or change the behaviour of the PHP runtime. On production environments such as shared servers, this is a **risk for other websites on the same server**.

#### ✅ How to work around it:

Drupal (and libraries such as Symfony) typically use `putenv()` to load variables from `.env` files. **This is easy to work around**:

**1. Don't use an `.env` file** – set the values you need directly in `settings.php` instead:

```php
$_ENV['VARIABLE_NAME'] = 'value';
$_SERVER['VARIABLE_NAME'] = 'value';
```

  
**2.** If you use your own `.env` loading, replace it with loading the file manually without `putenv()`:

```php
$env = parse_ini_file(__DIR__ . '/../.env', false, INI_SCANNER_RAW);
if ($env === false) {
    throw new RuntimeException('Cannot read .env');
}
foreach ($env as $k => $v) {
    $_ENV[$k] = $v;
    $_SERVER[$k] = $v;
}
```

 If the website still tries to call `putenv()`, some part of the application (e.g. a library that loads .env variables) is not configured correctly for our hosting. We recommend disabling or replacing these libraries by setting the variables manually in `settings.php`.
