Correctly write config file and also properly avoid php errors with some extra safety belts