2.6 KiB
title: Environment Types summary: Configure your SilverStripe environment to define how your web application behaves.
Environment Types
SilverStripe knows three different environment types (or "modes"). Each of the modes gives you different tools
and behaviors. The environment is managed by the SS_ENVIRONMENT_TYPE
variable through an
environment configuration file.
The three environment types you can set are dev
, test
and live
.
Dev
When developing your websites, adding page types or installing modules you should run your site in dev
. In this mode
you will see full error back traces and view the development tools without having to be logged in as an administrator
user.
Test Mode
Test mode is designed for staging environments or other private collaboration sites before deploying a site live.
In this mode error messages are hidden from the user and SilverStripe includes BasicAuth integration if you
want to password protect the site. You can enable that by adding this to your mysite/_config/app.yml
file:
---
Only:
environment: 'test'
---
SilverStripe\Security\BasicAuth:
entire_site_protected: true
Live Mode
All error messages are suppressed from the user and the application is in it's most secure state.
Checking Environment Type
You can check for the current environment type in config files through the environment
variant.
mysite/_config/app.yml
---
Only:
environment: 'live'
---
MyClass:
myvar: live_value
---
Only:
environment: 'test'
---
MyClass:
myvar: test_value
Checking for what environment you're running in can also be done in PHP. Your application code may disable or enable certain functionality depending on the environment type.
use SilverStripe\Control\Director;
if (Director::isLive()) {
// is in live
} elseif (Director::isTest()) {
// is in test mode
} elseif (Director::isDev()) {
// is in dev mode
}