Search code examples
codeigniternginxcodeigniter-2fastcgi

Nginx fastcgi param doesn't get to CodeIgniter


I have set a fastcgi_param ENVIRONMENT at nginx virtual host file, but I can't access that value inside CodeIgniter:

var_dump(defined('ENVIRONMENT')); //outputs false

Full nginx virtual host file:

server {
    listen      80;

    # Hostnames alias
    server_name webapp1;

    root /home/edson/repositorios/webapp1;

    index       index.php index.html;

    location /bec/admin {
        try_files $uri $uri/ /bec/admin/index.php$is_args$args;
    }
    location /bec {
        try_files $uri $uri/ /bec/index.php$is_args$args;
    }

    #
    # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include /etc/nginx/php.conf;
        fastcgi_param ENVIRONMENT development;
    }

    # Nginx Cache Control for Static Files (Browser Cache Control Directives)
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|xls|xlsx|doc|docx|csv|txt)$ {
        access_log        off;
        log_not_found     off;
        expires           max;
    }

    #
    # deny access to .htaccess files, and hidden files, which starts with dot (.), if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
    }
}

Am I doing something wrong?


Solution

  • That is a environment variable, so it can be accessed through getenv:

    Gets the value of an environment variable

    Example

    getenv('ENVIRONMENT');