Custom install profile fails at creating folders I have a relatively simple custom installation profile for Drupal 8.
All it does is:  


Ask for the sites domain name and the name of the theme it should scaffold.


Use the domain name to create the proper multi-site folder in /sites/&lt;domain-name&gt;
Use the theme name to create a theme folder under the multisite folder: /sites/&lt;domain-name&gt;/themes/custom/&lt;theme-name&gt;
Copy the relevant example files to the domain and theme folder, from the default site.



The problem I'm having is that it fails at creating the folders, due to it not being permitted to create the folders.
The /sites is set to permission 0755, and the problem is only fixed if I set sites to have permission 0777.

The folders are created using PHP's mkdir() function, as is set to create the folders recursively.

Questions:


Is there a better way to make folders during installation, than using php's mkdir(), that would fix my permission issue?
My assumption would be that the script (drupals installation UI) is being run as a different user than the one who owns the folder/filers of the site (installed via cli git and composer). How to I check which user the script is being run under? (using apache2 on centos7, in case it is relevant)
You've setup the Drupal code from the command line and now run the install from UI? Then this is normal if you have different users for the command line and the webserver, which is recommended. Only cheap hosters use one user for both. Drupal is supposed to have write access only for the sites/*/files folder and temporarily for settings.php during installation.

So you need to run this from the command line. Build the folders in a script or install the profile with a console command, which probably works without that you need to change anything in code.

Btw. this is why installing Drupal from the command line is so efficient, you get the permissions right from the start.