I am attempting to run a command as root from a php page, is there any way to run shell_exec("su - root -c 'apt-get update'") (for example) and pass the password to the shell? Or is there another way to run a root command from php and pass the password to the command.

The webserver runs as www-data, so it is not in the sudoers file, and I don't want to add www-data to the /etc/sudoers file, since that can cause security issues. So running "echo password | sudo -S apt-get update" will still fail.... I need a way to pass the password to "su -root" or something similar.