I'm quite new to Magento and have no idea if this is regular behaviour, but it doesn't seem to me like it is.
Whenever I try to install an extension (through the extension manager), it successfully runs through all the tests, creates a backup and starts installing the extension. Whenever it completes, however, I get thrown out and all there is to see is an HTTP 500 error.
This is then fixed by me running a chown command in terminal, setting the ownership of my Magento folder (and all underlying sub-folders/files) to the usergroup of www-data (the user running apache2).
After running this command everything works like it's supposed to and I get welcomed back into the system by a page stating the installation of the extension has succeeded.
Is there any way to make it so that the ownership of the added files/folders is automatically set to the usergroup of the apache2 user upon installation?
I'm running the latest version of Magento (2.2.2) on a Ubuntu 16.04 dedicated server.
Have you checked the instructions provided in this official guide? http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html
What user and group to the files that get installed by Magento get added as?
Oddly enough, the extension files themselves don't seem to be the problem.
Their ownership gets assigned to my Magento admin user and the www-data group. Yet, I still get the HTTP 500 error, which is fixed by chowning the entire Magento installation folder.
Narrowing down precisely which files have the problematic permissions would be useful. It may be that it's still the extension files. Is there a group www-data that the www-data apache user is also in?
Can you also go into the installed extension directory and provide a list of the permissions that are assigned, please?