Environment settings and secrets
This page is for application creators who handle settings that differ per machine and secrets such as API keys and passwords. Both must stay out of the code repository.
Contents
Settings per environment
From Settings per environment (EXP_ENV):
- Copy
config.env.php.exampletoconfig.env.phpand setdefine( 'EXP_ENV', 'test' );. It is read beforeconfig.phpby web and command line, and.gitignorekeeps it out of version control. - Put the environment's settings in a variant file: the environment name right after
.ini(settings/override/site.ini.test.append.php,extension/<ext>/settings/site.ini.test.append.php). - Clear the INI cache once; each environment has its own cache files.
Typical variants: the mail transport (file outside production), debug output, hosts, the Solr address.
Where secrets live
| Secret | Where |
|---|---|
| Database password | settings/override/site.ini.append.php of the installation |
| Your application's API keys | settings/override/<yourfile>.ini.append.php, mode 0640 |
| Provider keys of expai | settings/override/expai.ini.append.php only |
| Form token secret | [HTMLForms] Secret in settings/override/ |
Never in: your extension's repository, a .ini file the web server might show (use .ini.append.php, which wraps the
content in a PHP comment), templates, job payloads, logs, URLs or commit messages.
Reading secrets in code
$key = eZINI::instance( 'expdemo.ini' )->variable( 'ArchiveSettings', 'ApiKey' );
if ( $key === '' )
throw new RuntimeException( 'expdemo.ini [ArchiveSettings] ApiKey is not set; put it in settings/override/expdemo.ini.append.php' );Ship the key in your extension's expdemo.ini as an empty value with a comment, so installations see where to set it.
Checklist
- To do:
config.env.phpstays out of Git (the shipped.gitignorelists it); in a project repository of your own, keepsettings/override/out of version control too. - To do: Secrets have mode 0640 and belong to the web server's group.
- To do: Each environment has its own keys; production keys are never on development machines.
- To do: A leaked key can be revoked without a code change.
Demo mode. The environment variable EXP_DEMO_MODE=1 belongs to public demos only: an app that talks to a demo gets HTTP 403 when it tries to change or reset an administrator's password. Environment variables, Demo mode.
Related pages
- Settings and INI files in your application
- Security for applications
- Security standard
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.