---
title: "Environment"
manual: "TYPO3 Explained"
version: "main"
permalink: "https://docs.typo3.org/permalink/t3coreapi:environment@main"
source: "ApiOverview/Environment/Index.rst"
rendered: "2026-09-18T15:39:49+00:00"
---

# Environment {#environment}

The TYPO3 Core includes an environment class that contains all
environment-specific information, mostly paths within the
filesystem.

The fully qualified class name is `\TYPO3\CMS\Core\Core\Environment`. The
class provides static methods to access the necessary information.

To simulate environments in testing scenarios, the `initialize()`-method can
be called to adjust the information.

**Table of Contents**

-   [Environment PHP API](https://docs.typo3.org/permalink/t3coreapi:environment-php-api@main)

## Environment PHP API {#environment-php-api}

> [!TIP]
> A comprehensive list of methods can be found in the
> Class Reference: `Environment`

<!-- TODO: no Markdown rendering for "versionchanged" -->

Method Environment::getComposerRootPath() has been removed.Instead of calculating relative paths manually, use absolute paths or the
appropriate TYPO3 APIs for path handling, Environment::getProjectPath()

### `getProjectPath()` {#environment-project-path}

The environment provides the path to the folder containing the `composer.json`.
For projects without Composer setup, this is equal to [getPublicPath()](https://docs.typo3.org/permalink/t3coreapi:environment-public-path@main).

### `getPublicPath()` {#environment-public-path}

The environment provides the path to the public web folder with
`index.php` for the TYPO3 frontend. This was previously `PATH_site`.
For projects without Composer setup, this is equal to [getProjectPath()](https://docs.typo3.org/permalink/t3coreapi:environment-project-path@main).

### `getVarPath()` {#environment-var-path}

The environment provides the path to the `var/` folder. This folder contains
data like logs, sessions, locks, and cache files.

For Composer-based installations, it returns [var/](https://docs.typo3.org/permalink/t3coreapi:directory-var@main), in Classic mode
installations [typo3temp/var/](https://docs.typo3.org/permalink/t3coreapi:classic-directory-typo3temp-var@main).

**EXT:my_extension/Classes/MyClass.php (excerpt)**

```php
use TYPO3\CMS\Core\Core\Environment;

// Composer-based installations: '/path/to/my-project/var/`
// Classic mode installations: '/path/to/my-project/typo3temp/var/'
$pathToLabels = Environment::getVarPath();
```

### `getConfigPath()` {#environment-config-path}

In Composer-based installation this method provides the path
[config/](https://docs.typo3.org/permalink/t3coreapi:directory-config@main), in Classic mode installations
[typo3conf/](https://docs.typo3.org/permalink/t3coreapi:classic-directory-typo3conf@main).

The directory returned by this method contains the folders `system/`
containing the [configuration files](https://docs.typo3.org/permalink/t3coreapi:configuration-files@main)
`system/settings.php` and `system/additional.php` and the folder
`sites/` containing the [site configurations](https://docs.typo3.org/permalink/t3coreapi:sitehandling@main).

**EXT:my_extension/Classes/MyClass.php (excerpt)**

```php
use TYPO3\CMS\Core\Core\Environment;

// Composer-based installations: '/path/to/my-project/config/system/settings.php`
// Classic mode installations: '/path/to/my-project/typo3conf/system/settings.php'
$pathToSetting = Environment::getConfigPath() . 'system/settings.php';

// Composer-based installations: '/path/to/my-project/config/sites/mysite/config.yaml`
// Classic mode installations: '/path/to/my-project/typo3conf/sites/mysite/config.yaml'
$pathToSiteConfig = Environment::getConfigPath() . 'sites/' . $siteKey . '/config.yaml';
```

### `getLabelsPath()` {#environment-labels-path}

The environment provides the path to [var/labels/](https://docs.typo3.org/permalink/t3coreapi:directory-var-labels@main) in
Composer-based installations, respective [typo3conf/l10n/](https://docs.typo3.org/permalink/t3coreapi:classic-directory-typo3conf-l10n@main)
folder in Classic mode installations. This folder contains downloaded translation files.

**EXT:my_extension/Classes/MyClass.php (excerpt)**

```php
use TYPO3\CMS\Core\Core\Environment;

// Composer-based installations: '/path/to/my-project/var/labels/`
// Classic mode installations: '/path/to/my-project/typo3conf/l10n/'
$pathToLabels = Environment::getLabelsPath();
```

### `getCurrentScript()` {#environment-current-script}

Returns the path and filename to the current PHP script.

### `getContext()` {#environment-context}

Returns the current [Application context](https://docs.typo3.org/permalink/t3coreapi:application-context@main), usually defined via the `TYPO3_CONTEXT` environment variable.
May be one of `Production`, `Testing`, or `Development` with optional sub-contexts like `Production/Staging`.

Example, test for production context:

**config/system/additional.php | typo3conf/system/additional.php**

```php
use TYPO3\CMS\Core\Core\Environment;

$applicationContext = Environment::getContext();
if ($applicationContext->isProduction()) {
   // do something only when in production context
}
```
