I would suggest writing a shell script that will call useradd via sudo.
You can add specific commands for specific users to / etc / sudoers (edited by visudo)
There should be something like this:
Cmnd_Alias USERADD = /bin/sbin/useradd *
apache ALL=(USERADD) NOPASSWD:USERADD
call useradd:
sudo /usr/sbin/useradd USERNAME
Remember to confirm your entry in both the php script and the shell script.
source share