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.
I would prefer not to do the follow:
edit the /etc/sudoers file;
install the ssh2 php extension;
Used an entirely PHP based SSH implementation called phpseclib.
This way the user doesn’t have to install a php extension like ssh2, just download the files and include them in your script. Then you can pipe the password to the command, like so:
This php code will return the value “root”. Any commands you run at this time will be run as root.