I'm writing a PHP program that calls bash scripts. I'm using Linux (Centos). I'm trying to create a new user in Linux by entering username and password in the PHP page. this is the script I'm using:
egrep "^$1" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$1 exists!"
exit 1
else
sudo useradd -m -p $2 $1
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
this is how I call the script from PHP:
echo exec("/var/www/html/addUser.sh ".$username." ".$password);
it works when running it from terminal, but when calling the script from PHP it doesn't work. it is a matter of permissions. what should I do in order to allow the PHP (apache) to also add users? I've tried adding 'apache' to visudo both as user and as a group:
%apache ALL=(ALL) NOPASSWD: ALL
apache ALL=(ALL) ALL
it still doesn't work. any ideas? thanks.
%apache ALL=(ALL) NOPASSWD: ALLborders on criminally insane.