Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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