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

北战南征 提交于 2019-11-29 00:42:45

问题


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?


回答1:


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




回答2:


Just in case you are using nginx, here is the configuration you have to add inside vhosts configuration:

  server {

        location ~ \.php$ {
            fastcgi_param CI_ENV production;
        }

save and run nginx syntax check (just to avoid you from cursing me):

nginx -t

if you having issues or you cant find the parameter, you can follow the answer below: Nginx variables similar to SetEnv in Apache?




回答3:


It is a convention used by codeigniter. It helps the framework function 'out of the box'.



来源:https://stackoverflow.com/questions/36051146/codeigniter3-why-would-serverci-env-ever-be-set-in-the-first-place

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!