Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ############################## |
| 2 | Handling Multiple Environments |
| 3 | ############################## |
| 4 | |
| 5 | Developers often desire different system behavior depending on whether |
| 6 | an application is running in a development or production environment. |
| 7 | For example, verbose error output is something that would be useful |
| 8 | while developing an application, but it may also pose a security issue |
| 9 | when "live". |
| 10 | |
| 11 | The ENVIRONMENT Constant |
| 12 | ======================== |
| 13 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 14 | By default, CodeIgniter comes with the environment constant set to use |
| 15 | the value provided in ``$_SERVER['CI_ENV']``, otherwise defaults to |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 16 | 'development'. At the top of index.php, you will see:: |
| 17 | |
Phil Sturgeon | dda21f6 | 2012-06-03 10:36:36 -0500 | [diff] [blame] | 18 | define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); |
| 19 | |
| 20 | This server variable can be set in your .htaccess file, or Apache |
| 21 | config using `SetEnv <https://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv>`_. |
| 22 | Alternative methods are available for nginx and other servers, or you can |
Andrey Andreev | 815ac8a | 2014-10-28 21:32:20 +0200 | [diff] [blame] | 23 | remove this logic entirely and set the constant based on the server's IP address. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 24 | |
| 25 | In addition to affecting some basic framework behavior (see the next |
| 26 | section), you may use this constant in your own development to |
| 27 | differentiate between which environment you are running in. |
| 28 | |
| 29 | Effects On Default Framework Behavior |
| 30 | ===================================== |
| 31 | |
| 32 | There are some places in the CodeIgniter system where the ENVIRONMENT |
| 33 | constant is used. This section describes how default framework behavior |
| 34 | is affected. |
| 35 | |
| 36 | Error Reporting |
| 37 | --------------- |
| 38 | |
| 39 | Setting the ENVIRONMENT constant to a value of 'development' will cause |
| 40 | all PHP errors to be rendered to the browser when they occur. |
| 41 | Conversely, setting the constant to 'production' will disable all error |
| 42 | output. Disabling error reporting in production is a :doc:`good security |
| 43 | practice <security>`. |
| 44 | |
| 45 | Configuration Files |
| 46 | ------------------- |
| 47 | |
| 48 | Optionally, you can have CodeIgniter load environment-specific |
| 49 | configuration files. This may be useful for managing things like |
| 50 | differing API keys across multiple environments. This is described in |
Andrey Andreev | 7d19161 | 2015-05-13 11:20:44 +0300 | [diff] [blame] | 51 | more detail in the environment section of the :doc:`Config Class |
Andrey Andreev | e17dbe6 | 2015-07-20 10:32:36 +0300 | [diff] [blame] | 52 | <../libraries/config>` documentation. |