PHP Unit / Composer running as root

PHP Unit / Composer running as root

by Gareth J Barnard -
Number of replies: 2
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello,

When running PHP Unit (https://docs.moodle.org/dev/PHPUnit) on Moodle 3.9 on Ubuntu 20.04 with Apache in the www-data user and group and following https://docs.moodle.org/39/en/Installing_Moodle_on_Debian_based_distributions then Composer complains that:

PHP Unit initialisation

it should not be run as 'root' and yet unless I do 'sudo' then the php process won't work.  Also https://docs.moodle.org/39/en/Installing_Moodle_on_Debian_based_distributions seems to contradict https://docs.moodle.org/39/en/Installing_Moodle#Download_and_copy_files_into_place, where the first makes the Moodle code files writable by the web server user 'www-data' and the second by 'root' and says that the files should not be writable by the web server!

So how do you run composer / PHP Unit not as 'root' and get things to work please?

Gareth

Average of ratings: -
In reply to Gareth J Barnard

Re: PHP Unit / Composer running as root

by Mark Sharp -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

You're running the unit test under your own user 'gareth', try running it as www-data.

$ sudo -u www-data php admin/tool/phpunit/cli/init.php
In reply to Mark Sharp

Re: PHP Unit / Composer running as root

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thank you Mark!  That is really helpful smile.  I did have to change the owner and group of the parent folder to the code folder ('/var/www/moodle') being '/var/www' to 'www-data' to stop a composer install write permission issue.  So then ran:

sudo -u www-data composer install --no-plugins --no-scripts
sudo -u www-data php admin/tool/phpunit/cli/init.php

in '/var/www/moodle'.

That just leaves the oddity with the install docs!  Over having '/var/www/moodle' as 'root' or 'www-data', so posted: https://moodle.org/mod/forum/discuss.php?d=412367 - as a separate question pertaining to that area.

G


Attachment install_start.png