Hand-editing wp-config.php over SSH is how a missing semicolon takes a site down. WP-CLI can do the edit for me.
The wp config set command writes a constant into the file. The one flag to remember is --raw. Without it, WP-CLI wraps the value in quotes, and 'true' as a string is not the boolean you meant.
wp config set WP_DEBUG true --raw
wp config get WP_DEBUG
wp config set WP_MEMORY_LIMIT 256M
The first line sets a real boolean. The second reads it back. The third sets a string on purpose, so no --raw there. If the constant does not exist yet, WP-CLI adds it above the “stop editing” comment, which is the right place.
Use wp config set --no-add if you only want to change something that already exists and fail otherwise. That helps in scripts, where a typo in the name should be an error, not a new constant.
The caveat: this edits the live file. I would take a copy of wp-config.php first, and I would not use it for anything fancy such as a value built with PHP code. The command is made for plain constants and variables.
Further reading: wp config set (WP-CLI command reference), On this site: wp option list –autoload=on –format=total_bytes shows what every page load drags along, On this site: –skip-plugins and –skip-themes get WP-CLI working on a broken site