phplinuxpermissionssystemctl

php in-browser script cant restart/stop/start proccess


I have a simple script, which must restart the proccess on server: exec("systemctl stop listener.service"); This script cannot be executed from browser and i don't know what's wrong with him. Because if i run: exec("systemctl status listener.service | grep Active"); it works!

I tried:

$command = "systemctl stop listener.service";
system($command);
shell_exec($command);
exec($command);

$command = "sudo systemctl stop listener.service";
system($command);
shell_exec($command);
exec($command);

I've added "%www-data ALL=(ALL:ALL) ALL" thought visudo. Browser shows 0 errors (error reporting is enabled, i tried to make mistakes especially - its shown in browser, but this script show 0 errors. I've closed all tags as its needed.

Nothing is works.

I even tried to run python script from php - it's still doesn't work. If Im trying to run script from server console - it works, even if i dont giving root access to script. If Im trying to run script from server "php -a" console - it works, but it dont works from browser. Idk what is wrong with this script...


Solution

  • Finally, i've to add directive using "sudo visudo":

    %www-data ALL=(ALL) NOPASSWD: ALL
    

    And now its working. Thanks to @Barmar