I want to run a “sudo” command from the PHP and I have read all the tutorials on the web, but no solution works. At least I’ve added the default “nobody” user of LAMP to the root group – but no effect.
echo exec("sudo echo hi");
A note on security:
While some people here are downvoting this due to their strong belief that this will create a big security hole that will destroy the entire Internet, there are some valid cases for this, e.g., in testing. Running setup scripts from PHPUnit / Behat suites to configure the environment may require sudo permission. Those scripts are not accessible from the application and do not create security holes, as the matter of fact they help to ensure such holes are not present.
Adding users to the root group does not give them sudo rights, that is what /etc/sudoers is for.
To be honest, what you’re trying to do sounds like a giant security hole
EDIT: copied from comments…
My suggestion would be something like, setting up a cron under the root user, that checks against a file or db that your PHP can write to, parses it, and remove the users you’ve specified.