![]() |
$_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? (/showthread.php?tid=62111) Pages:
1
2
|
$_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - cupboy - 06-10-2015 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. RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - CroNiX - 06-10-2015 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 RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - cupboy - 06-10-2015 Looks like something I don't have access to on the server. Thanks for the info. RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - mwhitney - 06-11-2015 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. RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - cupboy - 06-11-2015 (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). It's not set to 'development' so it's being changed somewhere. The define code hasn't been modified. RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - CroNiX - 06-11-2015 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. RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - kilishan - 06-11-2015 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. RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - lexxtoronto - 06-12-2015 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'); RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - allenlee - 03-14-2016 I really think PHP Code: $_SERVER['CI_ENV'] Why not just use PHP Code: define('ENVIRONMENT', 'development'); Let's make thing simple. RE: $_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? - kilishan - 03-14-2016 (03-14-2016, 12:32 AM)allenlee Wrote: I really think 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: 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 ![]() Code: $domain = ! empty($_SERVER['HTTP_HOST']) ? strtolower($_SERVER['HTTP_HOST']) : 'cli'; |