Forum archive
Rights source of confusion updating Drupal9
Trying to run Composer to update Drupal9. It says do not run as root/super user. If I try to run it as a normal user it says
[ErrorException]
file_put_contents(./composer.lock): failed to open stream: Permission denied
Do you have to just go to every file/directory and give the normal user access there? Same problem with running Bundle under Redmine and that's how I solved that one and that was a pain in the rear. Is there a safe/generic compromise to run updates or whatever where you can be a normal user, but have access to what you need?

So you probably want to run the commands as the webserver user. That requires that the whole webroot is owned by the webserver user. The way to do that directly would be to ensure the files are all owned by the webserver, then leverage 'su' to run as 'www-data'. You could do that like this:
But that's not very handy. So in v16.1 we introduced some (fairly basic) helper/wrapper scripts to easily allow you to run composer (and drush and drupal console) as the webserver user ('www-data'). As above, they rely on the whole webroot being owned by www-data.
Assuming that you don't have v16.1, you can still use the helper scripts, but you'll need to set the permissions for the webroot, then download the scripts and make them executable. You can do that like this:
Now you should be able to run 'turnkey-composer' (instead of 'composer') to update your Drupal install. Note that you can run it anywhere and it will use the default webroot (/var/www/drupal9).
Please let me know how you go, especially if you hit any issues. These scripts are new, we actually used them to install Drupal in the v16.1 appliances, so they work at least in a basic way, but more real-world usage may reveal some shortcomings that we have overlooked. So please share how you go.