$_SERVER['CI_ENV'] -- where is and ENVIRONMENT this set? |
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.
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
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. (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.
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.
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.
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.
I really think
PHP Code: $_SERVER['CI_ENV'] 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. (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 was something like this in CI's index.php file: Code: $domain = ! empty($_SERVER['HTTP_HOST']) ? strtolower($_SERVER['HTTP_HOST']) : 'cli'; |
Welcome Guest, Not a member yet? Register Sign In |