CodeIgniter 4 keeps settings in config classes in app/Config, and lets the .env file override them per server.
The .env file
CI_ENVIRONMENT—development(shows errors) orproduction(hides them). Alwaysproductionon a live site.app.baseURL— the site address, ending with/database.default.hostname,.database,.username,.password,.DBDriverencryption.key— create withphp spark key:generate
The name format is class.property: app.baseURL overrides $baseURL in app/Config/App.php.
Config classes
Each file in app/Config is a class, for example App.php, Database.php, Email.php, Filters.php, Routes.php.
Reading config in code
config('App')->baseURLconfig(\Config\Email::class)->fromEmailenv('MY_KEY', 'default')— read a raw.envvalue
Your own config
Create app/Config/Site.php that extends BaseConfig with public properties, then read it with config('Site').
Never commit .env to Git — it contains passwords.
Example
<?php
// app/Config/Site.php
namespace Config;
use CodeIgniter\Config\BaseConfig;
class Site extends BaseConfig
{
public string $siteName = 'AgyanAdda';
public string $whatsapp = '';
public int $perPage = 12;
}
// .env (overrides the class values)
// site.whatsapp = 919876543210
// In a controller or view:
$site = config('Site');
echo $site->siteName; // AgyanAdda
echo $site->whatsapp; // 919876543210 (from .env)
The .env line site.whatsapp overrides the $whatsapp property of the Site class, so each server can have its own value.