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 | |
Phil Sturgeon | dda21f6 | 2012-06-03 10:36:36 -0500 | [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 |
| 23 | remove this logic entirely and set the constant based on the HTTP_HOST or IP. |
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 |
| 51 | more detail in the environment section of the `Config |
| 52 | Class <../libraries/config.html#environments>`_ documentation. |