2014-10-13 10:52:19 +02:00
|
|
|
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
|
2017-08-30 00:41:01 +02:00
|
|
|
and behaviors. The environment is managed by the `SS_ENVIRONMENT_TYPE` variable through an
|
2014-10-13 10:52:19 +02:00
|
|
|
[environment configuration file](../../getting_started/environment_management).
|
|
|
|
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.
|
|
|
|
|
|
|
|
<div class="alert" markdown="1">
|
|
|
|
**dev mode should not be enabled long term on live sites for security reasons**. In dev mode by outputting back traces
|
|
|
|
of function calls a hacker can gain information about your environment (including passwords) so you should use dev mode
|
|
|
|
on a public server very carefully.
|
|
|
|
</div>
|
|
|
|
|
|
|
|
### Test Mode
|
|
|
|
|
|
|
|
Test mode is designed for staging environments or other private collaboration sites before deploying a site live.
|
|
|
|
|
2017-07-03 03:22:12 +02:00
|
|
|
In this mode error messages are hidden from the user and SilverStripe includes [BasicAuth](api:SilverStripe\Security\BasicAuth) integration if you
|
2018-06-25 00:39:53 +02:00
|
|
|
want to password protect the site. You can enable that by adding this to your `app/_config/app.yml` file:
|
2014-10-13 10:52:19 +02:00
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
|
|
|
|
```yml
|
2017-10-27 04:38:27 +02:00
|
|
|
---
|
|
|
|
Only:
|
|
|
|
environment: 'test'
|
|
|
|
---
|
|
|
|
SilverStripe\Security\BasicAuth:
|
|
|
|
entire_site_protected: true
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
2014-10-13 10:52:19 +02:00
|
|
|
|
|
|
|
### Live Mode
|
|
|
|
|
|
|
|
All error messages are suppressed from the user and the application is in it's most *secure* state.
|
|
|
|
|
|
|
|
<div class="alert">
|
|
|
|
Live sites should always run in live mode. You should not run production websites in dev mode.
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
## Checking Environment Type
|
|
|
|
|
|
|
|
You can check for the current environment type in [config files](../configuration) through the `environment` variant.
|
|
|
|
|
2018-06-25 00:39:53 +02:00
|
|
|
**app/_config/app.yml**
|
2017-10-27 04:38:27 +02:00
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
```yml
|
2017-10-27 04:38:27 +02:00
|
|
|
---
|
|
|
|
Only:
|
|
|
|
environment: 'live'
|
|
|
|
---
|
|
|
|
MyClass:
|
|
|
|
myvar: live_value
|
|
|
|
---
|
|
|
|
Only:
|
|
|
|
environment: 'test'
|
|
|
|
---
|
|
|
|
MyClass:
|
|
|
|
myvar: test_value
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
2014-10-13 10:52:19 +02:00
|
|
|
Checking for what environment you're running in can also be done in PHP. Your application code may disable or enable
|
2017-08-03 02:51:32 +02:00
|
|
|
certain functionality depending on the environment type.
|
2017-10-27 04:38:27 +02:00
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
```php
|
2017-10-27 04:38:27 +02:00
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
|
|
|
|
if (Director::isLive()) {
|
|
|
|
// is in live
|
|
|
|
} elseif (Director::isTest()) {
|
|
|
|
// is in test mode
|
|
|
|
} elseif (Director::isDev()) {
|
|
|
|
// is in dev mode
|
|
|
|
}
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
|
|
|
|
2017-11-27 04:39:17 +01:00
|
|
|
## Related Lessons
|
|
|
|
* [Advanced environment configuration](https://www.silverstripe.org/learn/lessons/v4/advanced-environment-configuration-1)
|