TYPO3 Extension Environment
Created by Benjamin Mack, b:dreizehn GmbH, in 2013.
Published under the MIT license., (*1)
What does it do?
The TYPO3 extension "Environment", compatible with TYPO3 CMS 4.5 until
TYPO3 CMS 7.99.99, allows for context-specific settings, so the TYPO3
installation has different options for each context. This means that all
logging and debugging settings can be turned on for the development
environment., (*2)
Of course, this extension makes most sense if you have multiple server scenarios and a local development environment., (*3)
Installation
1) Install the extension., (*4)
2) Add the following Rewrite statements to your .htaccess file after the RewriteBase
statement or to your Apache webserver configuration., (*5)
# Make sure the context variable is set with every http request
RewriteCond %{HTTP_HOST} ^(.*)staging-system\.org$
RewriteRule .? - [E=TYPO3_CONTEXT:Production/Staging]
RewriteCond %{HTTP_HOST} ^(.*)development-system\.org$
RewriteRule .? - [E=TYPO3_CONTEXT:Development]
3) Add the following code to your typo3conf/AdditionalConfiguration.php for
TYPO3 CMS >= 6.0, (*6)
// load the environment / context configuration for this installation
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('environment')) {
include('ext/environment/Includes/Bootstrap/InitializeContext.php');
}
3a) For installations prior to 6.0, please include this at the bottom of the localconf.php, (*7)
// load the environment / context configuration for this installation
if (t3lib_extMgm::isLoaded('environment')) {
include('ext/environment/Includes/Bootstrap/InitializeContext.php');
}
3b) For installations using TYPO3 CMS 6.2+, just add this to your typo3conf/AdditionalConfiguration.php, (*8)
// load the environment / context configuration for this installation
include('ext/environment/Includes/Bootstrap/InitializeContext.php');
After that, you have a PHP constant named "TYPO3_CONTEXT" that
is set to the environment variable placed in your server settings., (*9)
4) You can now define context-specific configurations, and create files like, (*10)
- typo3conf/AdditionalConfiguration.Development.php
- typo3conf/AdditionalConfiguration.Production.php
and add configuration options like different DB settings and debugging
settings, that get included depending on what context you have set in your
server settings. Examples are provided in
Resources/Public/Examples., (*11)
Please make sure that the PHP files always start with the following lines, (*12)
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
Best practices
Development Environment "Development", (*13)
- mails should only be sent locally
- all debug modes are set to full logging
- caching is disabled by default
Integration Environment "Testing/Integration", (*14)
- testing environment for unit tests etc.
"Production/Staging" Environment, (*15)
- Clone of the "Live" server for (customer) acceptance testing
"Production" Environment
* "Live" server, (*16)
The top-level contexts, however, must be one of "Testing", "Development" and "Production". Of course any other sub-context name can be chosen., (*17)
Setting the environment for scheduler tasks
Usually the TYPO3 scheduler is called like this:, (*18)
/usr/bin/php5 /path/to/my/typo3/installation/typo3/cli_dispatch.phpsh scheduler, (*19)
this should be modified at all times to set the environment variable, (*20)
/usr/bin/php5 /path/to/my/typo3/installation/typo3/cli_dispatch.phpsh scheduler --context=Production, (*21)
Environment-dependent TypoScript
You can check the environment with the following TypoScript condition., (*22)
# disable tracking for Production/Staging environment
[globalString = ENV:TYPO3_CONTEXT = Production/Staging]
page.20 >
[GLOBAL]
With TYPO3 CMS 6.2, you can use the newly defined "applicationContext" TypoScript condition., (*23)
Environment-dependent email redirection
You can redirect any outgoing email to a specific email address by setting the
following TYPO3_CONF_VARS option:, (*24)
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['environment']['redirectEmails'] = 'benni@typo3.org';, (*25)
You can add multiple addresses separated via comma, or in a simple array., (*26)
It makes most sense if you put this in a environment-dependent installation like
typo3conf/AdditionalConfiguration.Development.php and remove it in the
Production environment settings., (*27)
Thanks
Big thanks goes to:, (*28)
- the b13 specialists for braining and finding the optimal out-of-the-box solutions,
- Jesus Christ who saved my life.