But as I know Zend Framework 2 can not write to config files.
Yes it can. It has whole Zend\Config\Writer
component. If you are using default php array config files, you can alter config file like this:
$path = 'config/autoload/local.php';
$config = include $path;
$config['key'] = 'new value';
$writer = new \Zend\Config\Writer\PhpArray();
$writer->toFile($path, $config);
Do not forget to delete the config cache, if you are using one.
But I think there is better way to do this - instead of altering config files, you could prepare config template for each server and easily swap them. So in config/autoload
directory you would have files adresses.local.server1.php.dist
and adresses.local.php.dist
containing address config for every server you need. Then if you need to use config for server1, just copy it:
$ cp adresses.local.server1.php.dist adresses.local.php