Lesson 8.3: Changing settings with exp:ini
exp:ini reads and changes settings in every scope, line by line, keeping comments and order, with a backup and an
audit record for every write. It is the safe replacement for editing settings files by hand or with sed. In this
lesson learners use its actions, preview changes, and move settings that collected in the global override into their
extension, where they travel with the code.
At a glance
| Course | Developers |
| Module | Module 8: Settings and siteaccesses |
| Duration | 50 minutes (15 presenting, 35 exercise) |
| Level | Intermediate |
| Audience | Developers and administrators |
| Prerequisites | Lesson 8.2 |
Learning objectives
After this lesson, learners can:
- use
get,set,add,rem,clear,toggleandcopywith the right scope; - preview any change with
--dry-runand find the backup of a written file; - read the exit code of a command for scripts;
- move a block of settings into an extension with
move; - explain what
exp:inidoes with secrets and with the INI cache.
Trainer's notes
How to present it
Sources: Change settings from the command line: exp:ini and the full reference console exp:ini.
- Five commands for a day (4 minutes).
set,get,toggle,where,rem. A setting is<file>/<Block>/<Variable>;.iniis optional; arrays end in[], hash entries areVariable[key]. - Safety (3 minutes). Each changed file is copied to
var/backup/ini/<timestamp>/first (mode 0600); writes are atomic and refused if the file changed meanwhile (exit 4); a write is recorded in the audit trail assystem.setting.write; after a write the INI cache tag is cleared. - Secrets (2 minutes). Variables named like Password, Secret, Token, ApiKey and similar are shown as
********;--show-secretsshows them. - Exit codes (2 minutes). 0 done or nothing to change, 1 usage error, 2 not found, 3 refused, 4 write failed. Scripts can rely on them.
- Moving into an extension (4 minutes).
exp:ini move <file>/<Block> <from> <to>writes the target first, then removes the block from the source;--dry-runshows both diffs;--create-extensioncreates a new extension for the move.
Common questions
Is exp:ini the same as php bin/php/ini.php? Yes; the console runs that script.
Why does a change not show on Velocity? Velocity's workers keep the settings of their warm-up; they see the
change after exp:velocity restart (lesson 13.2).
Can I add my own action? Yes: actions and scope providers are classes registered in settings/ini.ini [IniCommandSettings].
Pitfalls
- Running as root.
exp:inikeeps owner and group of changed files, but a new file created as root can break the site. Run as the site user. - Forgetting the scope.
setneeds a scope;getwithout one shows the value in effect. - Writing the default scope.
settings/<file>.iniis refused unless--allow-default; do not use it.
Hands-on exercise
On the development installation.
List the actions:
php bin/php/console exp:ini actions.Set the site name for your public siteaccess, previewing first:
php bin/php/console exp:ini set site.ini/SiteSettings/SiteName "Developer course" siteaccess:<sa> --dry-run php bin/php/console exp:ini set site.ini/SiteSettings/SiteName "Developer course" siteaccess:<sa>Find the backup:
ls var/backup/ini/.Toggle the view cache globally and back:
php bin/php/console exp:ini toggle site.ini/ContentSettings/ViewCaching global(run it twice).Add and remove an array value:
php bin/php/console exp:ini add site.ini/DebugSettings/DebugIPList[] 127.0.0.1 global php bin/php/console exp:ini add site.ini/DebugSettings/DebugIPList[] 127.0.0.1 global php bin/php/console exp:ini rem site.ini/DebugSettings/DebugIPList[] 127.0.0.1 globalAsk for a setting nobody sets and read the exit code:
php bin/php/console exp:ini get site.ini/MySettings/Nothing; echo "exit $?".Move the
[TemplateSettings]block ofsite.inifrom the global override into your extension, previewing first:php bin/php/console exp:ini move site.ini/TemplateSettings global extension:mysite_hello --dry-runRead both diffs. Run it without
--dry-runonly if the block holds development settings you want in the extension; otherwise stop here.Read the JSON form of one command:
php bin/php/console exp:ini get site.ini/SiteSettings/SiteName --json.
Expected result
- Step 2: the dry run prints a diff and "nothing written"; the real run names the file written.
- Step 3: a timestamped folder with the copy of the changed file.
- Step 5: the second
addsays "Nothing to change";remremoves the value. - Step 6:
exit 2. - Step 7: two diffs, the target extension file and the global override.
- The trainer asks each learner what exit code 3 means.
Quiz
- Which option shows a change without writing it?
- Which exit code means "refused"? A. 1 B. 2 C. 3 D. 4
- Where is the backup of a file changed by
exp:ini? - What does
exp:ini movewrite first: the target or the source? - How are passwords shown by
get,listandwhere?
Answers
--dry-run.- C. 3: for example the default scope, an unknown siteaccess, or a move that would change a value in effect.
- In
var/backup/ini/<timestamp>/<path>. - The target, then the block leaves the source.
- As
********, unless--show-secretsis given.
Further reading
- Change settings from the command line: exp:ini.
- console exp:ini: every action, option and exit code, with output.
- Audit trail: where settings writes are recorded.
Related pages
- Module 8: Settings and siteaccesses
- Developers: course overview
- Trainers: start here
- 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.