I have a problem to run a command that requires root privileges via php on the apache server
- I added a command to sudoers so that it does not require a password for the user
visudo:
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path = "/ usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL = (ALL: ALL) ALL
# Allow members of group sudo to execute any command
% sudo ALL = (ALL: ALL) ALL
# See sudoers (5) for more information on "#include" directives:
#includedir /etc/sudoers.d
www-data ALL = NOPASSWD: / sbin / iw
- Php script that I am trying to execute, I also check the error that is returned
<? php
echo '<pre>';
$ last_line = system ('sudo / sbin / iw wlan0 scan 2> & 1', $ retval);
// Printing additional info
echo '
</pre>
<hr /> Last line of the output: '. $ last_line. '
<hr /> Return value: '. $ retval;
?>
php script returns
sh: 1: sudo: not found
Last line of the output: sh: 1: sudo: not found Return value: 127
sudo is installed, and works fine when I execute from other user
whoami returns "www-data" so user is ok
www-data belongs to the
sudo group
groups www-data
www-data: www-data sudo
/
path separators and the redirection? are they actually in your sudoers file and php script? or are they some sort of copy-paste artifact?