Reputation: 469
My php script:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
exec('sudo /path/to/script.sh');
?>
my visudo line
www-data ALL=NOPASSWD: /path/to/script.sh
(I tripled checked every path)
If i remove the 'sudo' in the exec() it will execute (i put a touch aaa
at the start, with sudo the file isn't even created so the script doesn't even begin to execute). The script has exec rights for everyone.
I can't manage to get any error output. I can't su into www-data to try to launch it manually with sudo (when I su I get "This account is currently not available. ", but I guess that's normal behavior).
Upvotes: 0
Views: 540
Reputation: 177
1 -If you're working with RHEL/CentOS and the path is under the /root path you can't execute it.
2 - Check if the scrit have the 'x' flag (chmod +x /path/to/script.sh)
3 - Check if the user ww-data can execute the scrit with
sudo -u www-data script.sh
Upvotes: 0
Reputation: 44181
If your system has selinux or some other policy-based access control engine enabled, your web server process will be running under a constrained context which limits rights further. Verify whether you have selinux enabled.
Provide the full path to sudo
. While your shell may have it in its path, perhaps your web server does not.
Upvotes: 1