PHP:运行shell_exec或系统作为sudo?

I have a few commands I need to invoke from my PHP web application that can only run as sudo.

http://php.net/manual/en/function.shell-exec.php says (in the comments) that I can do the following:

system('echo <password> | sudo -u root -S <command>');

It doesn't work. I'm trying to do a groupadd, useradd, etc. Suggestions?

To add a user to the sudo list and have it not prompt for a password for a certain program... edit your /etc/sudoers file as such:

Cmnd_Alias BUNDLE = /usr/bin/bundle

deploy  ALL=(ALL) NOPASSWD:BUNDLE

Where deploy is the username and /usr/bin/bundle is the path the program that I want to access without password.

Presumably that would only work if the user php runs as (apache, nobody or something else, depending on the apache config) has sudo enabled without password for that command. Which is rather unlikely, given the wide, yawning security hole it would open.