Welcome Guest, Not a member yet? Register   Sign In
$_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set?
#1

(This post was last modified: 06-10-2015, 11:52 AM by cupboy.)

I read the skimpy documentation that suggests setting this in .htaccess but what are the other ways of doing it? I did a search on this and found nothing. I would like to figure out where this is set on the site I am working on. It's not in the .htaccess file.

Also where is the ENVIRONMENT constant set? I saw one place where the server variable CI_ENV is checked but this constant is being set or cleared elsewhere.
Reply
#2

It depends on what webserver you're using. If it's apache, you can place it in the main apache.conf, or the conf for your vhost.
http://httpd.apache.org/docs/2.2/env.html#setting

As far as where ENVIRONMENT is set, there's only one place and that's in the main index.php file. Everywhere else you check for (example)
if (ENVIRONMENT == 'production')
if (ENVIRONMENT == 'development')
etc
Reply
#3

(This post was last modified: 06-10-2015, 03:51 PM by cupboy.)

Looks like something I don't have access to on the server.  Thanks for the info.
Reply
#4

It's quite possible that the CI_ENV variable is not set at all, in which case the code normally included in the public index.php file sets the ENVIRONMENT to 'development' by default. I set CI_ENV to 'production' in a conf file on my production server, but I don't set it in my development environment(s).

If someone else setup your site, it's also possible that they changed the way ENVIRONMENT is defined, though you should be able to find it by searching for "define('ENVIRONMENT'".

In the past, I've seen some pretty elaborate methods of setting this to avoid having to change the index.php file for each environment, since the CI_ENV check is relatively new.
Reply
#5

(06-11-2015, 12:20 PM)mwhitney Wrote: It's quite possible that the CI_ENV variable is not set at all, in which case the code normally included in the public index.php file sets the ENVIRONMENT to 'development' by default. I set CI_ENV to 'production' in a conf file on my production server, but I don't set it in my development environment(s).

If someone else setup your site, it's also possible that they changed the way ENVIRONMENT is defined, though you should be able to find it by searching for "define('ENVIRONMENT'".

In the past, I've seen some pretty elaborate methods of setting this to avoid having to change the index.php file for each environment, since the CI_ENV check is relatively new.

It's not set to 'development' so it's being changed somewhere. The define code hasn't been modified.
Reply
#6

What webserver are you using? Did you check the webservers conf file for your site to see if it's setting the CI_ENV server variable there? That's really the only other place it could be set that I know of.
Reply
#7

If you're running Apache, you can also set this in your .htaccess file, I believe.

Code:
SetEnv CI_ENV production

Additionally, you can just do some logic in the main index.php file to check the current $_SERVER['HTTP_HOST'] to determine which environment should be set.
Reply
#8

I followed some examples and I tried to set it in .htaccess with some ifs depending on the url e.g. if it's localhost then set Development etc, and then setting it like this in index.php:

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

But it only worked on my localhost and not on my server. So I just hard coded in the index.php:

Code:
define('ENVIRONMENT', 'production');
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#9

I really think
PHP Code:
$_SERVER['CI_ENV'
is useless.

Why not just use
PHP Code:
define('ENVIRONMENT''development'); 
?

Let's make thing simple.
Personal blog: https://terryl.in
My personal project is called Dictpedia is currently using Codeigniter 3, welcome.
Reply
#10

(03-14-2016, 12:32 AM)allenlee Wrote: I really think
PHP Code:
$_SERVER['CI_ENV'
is useless.

Why not just use
PHP Code:
define('ENVIRONMENT''development'); 
?

Let's make thing simple.

To be fair, simple really depends on your workflow. To be able to set CI_ENV on a staging server and a production server in .htaccess (or equivalent), then simply have the code updated on pushes to master branch in git is super simple for that workflow. To require the deploy script to manually edit the index.php file to change the environment every time a push happens is potentially problematic.

For those that don't use it, it is effectively the same thing as define('ENVIRONMENT', 'development');

(06-12-2015, 06:49 AM)lexxtoronto Wrote: I followed some examples and I tried to set it in .htaccess with some ifs depending on the url e.g. if it's localhost then set Development etc, and then setting it like this in index.php:

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

But it only worked on my localhost and not on my server. So I just hard coded in the index.php:

Code:
define('ENVIRONMENT', 'production');

One way that I've handled this in other situations where CI_ENV wasn't available, or the client wasn't tech-savvy enough to set it keep it set Smile was something like this in CI's index.php file:

Code:
$domain = ! empty($_SERVER['HTTP_HOST']) ? strtolower($_SERVER['HTTP_HOST']) : 'cli';

if (strpos($domain, '.dev') !== false || $domain == 'cli')
{
   define('ENVIRONMENT', 'development');
}
else {
   define('ENVIRONMENT', 'production');
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB