Hello,
You don't need to change the core files. We recommend using putenv to set a custom HOME value dynamically if needed:
<?php
putenv("HOME=/var/www");
You don't need to copy LibreOffice to the folder .config. LibreOffice uses this folder for temp files, so the user that calls LibreOffice (for example www-data is a common default user of apache) must have rw access to that folder.
Regards.