Skip to content

Instantly share code, notes, and snippets.

@yidas
Last active March 27, 2020 17:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yidas/df94799bbb30a96a25f65fba85b254ab to your computer and use it in GitHub Desktop.
Save yidas/df94799bbb30a96a25f65fba85b254ab to your computer and use it in GitHub Desktop.
Codeigniter - Set environment when running in CLI mode

Codeigniter - Set environment when running in CLI mode

There are some ways to set environment when running in CLI mode for Codeigniter 3:

Set Var in Command Way:

$ CI_ENV="production" php index.php welcome/index

Create Bootstrap Way

You could create a bootstrap for CLI with production environment concern:

In Codeigniter webroot: ./cli-prod.php

if (php_sapi_name() !== 'cli') {
    
    die('Access Denied');
}

define('ENVIRONMENT', 'production');

require __DIR__ . '/index.php';

After that, run command likes:

php ./cli-prod.php controller/action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment