Skip to main content
Configuration

Configuration

CodeIgniter keeps configuration in PHP classes under app/Config. The .env file overrides selected values without changing those classes, so the same codebase can run in different environments.

Environments

CI_ENVIRONMENT changes framework behaviour. Development shows detailed errors and the debug toolbar. Production hides internal details, writes logs, and should be used for every public deployment.

CI_ENVIRONMENT = development

Reading values

$apiKey = env('app.apiKey', 'missing');

Use env() for values that differ between machines. Provide a fallback because missing keys return null.

Application URL

app.baseURL = 'https://example.com/'

Set the exact public address, including the trailing slash. Links, redirects, and uploaded file paths depend on it.

Database settings

Database credentials belong in .env, not in version control. Quote values that contain spaces, and use true or false for booleans.

Configuration caching

Production deployments can cache configuration for speed. Clear that cache during each release so changed values take effect.

Keep configuration safe

  • Never commit .env; commit an env template with placeholders instead.
  • Use different database users for development and production.
  • Grant the production database user only the permissions it needs.
  • Rotate secrets when team members leave or a key is exposed.
When behaviour differs between machines, compare the environment name and the effective .env values first. Most configuration surprises start there.