Attention
TYPO3 v9 has reached its end-of-life September 30th, 2021 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.
You can order Extended Long Term Support (ELTS) here: TYPO3 ELTS.
Environment¶
Since version 9.x the TYPO3 core includes an environment class.
This class contains all environment-specific information, e.g. paths within the
filesystem. This implementation replaces previously used global variables and
constants like PATH_site
.
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.
Environment PHP API¶
getProjectPath()¶
The environment provides the path to the folder containing the composer.json
.
For projects without Composer setup, this is equal to getPublicPath().
getPublicPath()¶
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().
getVarPath()¶
The environment provides the path to the var
folder. This folder contains
data like logs, sessions, locks, and cache files.
For projects with Composer setup, the value is getProjectPath() . '/var'
,
so it is outside of the web document root - not within getPublicPath()
.
Without Composer, the value is getPublicPath() . '/typo3temp/var'
, so within
the web document root - a situation that is not optimal from a security point of view.
getConfigPath()¶
The environment provides the path to typo3conf
. This folder contains TYPO3
global configuration files and folders, e.g. LocalConfiguration.php
.
For projects with Composer setup, the value is getProjectPath() . '/typo3conf'
,
so it is outside of the web document root - not within getPublicPath()
.
Without Composer, the value is getPublicPath() . '/typo3conf'
, so within
the web document root - a situation that is not optimal from a security point of view.
getLabelsPath()¶
The environment provides the path to labels
, respective l10n
folder. This folder contains downloaded translation files.
For projects with Composer setup, the value is getVarPath() . '/labels'
,
so it is outside of the web document root - not within getPublicPath()
.
Without Composer, the value is getPublicPath() . '/typo3conf/l10n'
, so within
the web document root - a situation that is not optimal from a security point of view.
getCurrentScript()¶
Returns the path and filename to the current PHP script.
getContext()¶
Returns the current Application Context, usually defined via the TYPO3_CONTEXT
environment variable.
May be one of Production
, Testing
, or Development
with optional sub-contexts like Production/Staging
.
Configuring Environment Paths¶
The TYPO3 constant PATH_site
acts as a basis for any PHP entry point. It
can be overwritten via the environment variable TYPO3_PATH_ROOT
.
The variable TYPO3_PATH_ROOT
is automatically calculated and set for any Composer-based TYPO3 installation,
making it possible to e.g. run the TYPO3 command line interface from any location.
The environment variable called TYPO3_PATH_APP
is used
to allow to store data outside of the document root.
All Composer-based installations benefit from this functionality, as data that was previously
stored and hard-coded within typo3temp/var/
is now stored within the project root folder var/
.
For non-composer installations (Classic Mode), it is possible to set the environment variable to a folder, usually one level upwards than the regular webroot. This increases security for any TYPO3 installation as files are not publicly accessible (for example via web browser) anymore.
A typical example:
TYPO3_PATH_APP
is set to/var/www/my-project
.The web folder is then set to
TYPO3_PATH_ROOT
/var/www/my-project/public
.
Non-public files are then put to
/var/www/my-project/var/session
(like Maintenance Tool Session files)/var/www/my-project/var/cache
(Caching Framework data)/var/www/my-project/var/lock
(Files related to locking)/var/www/my-project/var/log
(Files related to logging)/var/www/my-project/var/extensionmanager
(Files related to extension manager data)/var/www/my-project/var/transient
(Files related to import/export, core updater, FAL)
For installations without this setting, there are minor differences in the folder structure:
typo3temp/var/cache
is used instead oftypo3temp/var/Cache
typo3temp/var/log
is used instead oftypo3temp/var/logs
typo3temp/var/lock
is used instead oftypo3temp/var/locks
typo3temp/var/session
is used instead oftypo3temp/var/InstallToolSessions
typo3temp/var/extensionmanager
is used instead oftypo3temp/var/ExtensionManager
Important
Although it is a most common understanding in the TYPO3 world that typo3temp/
can be removed at any time,
it is considered bad practice to remove the whole folder. Developers should selectively remove
folders relevant to the changes made.