5

How can I change values of the .ini files via command line? (linux or windows)

For example I have a php.ini file:

display_errors = On
error_reporting = E_ALL & ~E_NOTICE

Now, I need be like this command:

MAGIC-COMMAND display_errors=Off error_reporting=E_ALL php.ini

And that options effective and write in php.ini file, and I have this content:

display_errors = Off
error_reporting = E_ALL

2 Answers2

2

Have a look at crudini, which runs on Linux and Windows, and supports many formats of ini files:

https://github.com/pixelb/crudini

Your example would be:

py crudini.py --set php.ini "" display_errors Off --set php.ini "" error_reporting E_ALL
pixelbeat
  • 1,380
1

This question is 5 years old and despite YAML having mostly replaced INI as the dominant config file format, editing INI files is still something you need to do sometimes – in my case to add or update access keys in my ~/.aws/credentials file, or, like the OP, to edit php.ini.

I googled for "command line ini file editor" and found initool. It seems to have been written in ML (I only remember that from university, can't believe people actually use this in real life!) so it requires an ML runtime (they use MLton), which isn't ideal, especially because MLton only has AMD64 releases and I'm on a Mac M1 which has an ARM64 processor, so the build fails for me.

But since it seems to be the only such tool around, I think I might spend a little bit of time to get their build to be more multi-arch aware and then use that to build a multi-platform Docker image.

Not really an answer (yet) but hopefully better than the comments so far that weren't particularly helpful (but fully on character for sysadmins):

  • sed really doesn't help here: the use case is to complicated because INI files have sections which are basically namespaces, so display_errors under section A is a different key from display_errors under section B – trying to do that with sed will be a nightmare, if it's even possible;
  • vi is an interactive editor and I'm pretty sure that when the OP asks for "via command line" they're not asking for an interactive text editor that you launch from the command line;
  • Not sure why "software recommendation" would be off-topic here – allowed topics are "computer software" – and the OP isn't asking for an opinion, they're asking for command-line INI-file editors that people use or are aware of.

Will update this if I have a PR on initool that will build a multi-platform Docker image.

Frans
  • 111
  • 2