Q . CodeIgniter3: Why would $_SERVER['CI_ENV'] ever be set in the first place?

Mike Tyson. asked, Feb 08 ' 2017

I see that in their default installation, their index.php has this: 

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

Why would CI_ENV ever already be set within the $_SERVER array?

  • codeignitor
  • codeignitor-3

1 Answers

As Oliver described; it's a special-use case for multiple environments. Splitting out the development, testing & production by means of .htaccess before it even gets to the code. To configure this:

Development (Localhost)

<IfModule mod_env.c>
    SetEnv CI_ENV development
</IfModule>

Testing (Your Local Server)

<IfModule mod_env.c>
    SetEnv CI_ENV testing
</IfModule>

Production (Remote Server)

<IfModule mod_env.c>
    SetEnv CI_ENV production
</IfModule>

You're right in thinking it won't ever change unless there's some manual intervention. There's not much documentation in regards to this:

"This server variable can be set in your .htaccess file, or Apache config using SetEnv. Alternative methods are available for nginx and other servers, or you can remove this logic entirely and set the constant based on the server’s IP address."

Source: Using the Environment Constant

Leave a Ansewer