Components
Enabling Twig debug info via Devel PHP is not something I recommend you to do but in some rare cases, you might have to do it. Here's how to do it:
use Symfony\Component\Yaml\Yaml;
$yaml = Yaml::parseFile('sites/default/default.services.yml');
$yaml['parameters']['twig.config']['debug'] = TRUE;
$updated_yaml = Yaml::dump($yaml);
file_put_contents('sites/default/services.yml', $updated_yaml);
Nothing fancy here. Just loading the default services file, changing one variable to TRUE and then saving the content to services.yml file.