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