Add user via occ via php

I try to add a user via occ command out of a PHP script, but there is no way i will find.

This works and i will get the settings of an existing user:

exec('/usr/bin/php74    occ user:setting "user" 2>&1',$test);
print_r($test);

But this not, because occ is expecting the password input by keyboard:

exec('/usr/bin/php74 -d memory_limit=512M   occ user:add  --display-name="Layla Smith"  2>&1',$test);

and the enviroment var cant be set with php:

exec('export OC_PASS=newpassword 2>&1',$test);
exec('/usr/bin/php74 -d memory_limit=512M   occ user:add  --password-from-env --display-name="Layla Smith"  2>&1',$test);

last try, like owncloud with an emailadress, will not work in Nextcloud:

exec('/usr/bin/php74 -d memory_limit=512M   occ user:add  --display-name="Layla Smith"  --email="test@test.de"    layla 2>&1',$test);

is there a way i forgott?
maybe a way thats works?

Perhaps it is not possible to use it in PHP with exec().
Please test all commands first without PHP.
If that works post your commands and perhaps than we find a php-script.

Hi devnull,

thank you for the offer.
I don’t have SSH access to this cloud, so i tried a lot with occ&PHP.
The last way was to pipe the password inside the exec() function.
But this will not work with an enabled save_mode, i read…

Instead i found the Nextcloud User Provisioning API :slight_smile:
with an example for CSV files and cut everything off i do’t need.

1 Like