我需要帮助,我有网络界面,可以在 php 中运行此部分:
$cmd="/usr/sbin/sudo /usr/sbin/service networking stop"
exec($cmd, $mes);
print_r($mes); #this is emptz message
$cmd="/sbin/ifconfig"
exec($cmd, $mes);
print_r($mes);
print_r($mes);对于停止服务为空 print_r($mes);对于 ifconfig=array 具有有关接口(interface)的所有信息(但所有信息都是向上而不是向下,因此上面的消息不能很好地工作(该服务仍在运行))
该脚本通过守护用户运行。
这是我的视觉效果:
# 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: /bin/nc, /bin/cp, /bin/chmod, /bin/chown, /etc/init.d/, /usr/sbin/service
deamon ALL = NOPASSWD: /bin/cp, /bin/chmod, /bin/chown, /etc/init.d/, /usr/sbin/service, /home/optokonlmcp/sss.php, /sbin/ifconfig
请问你知道为什么这个 php 脚本不起作用吗? 预先感谢您
BR MK
最佳答案
解决方案:
使用 rolus 为 root (root:root) 创建 sctipt 并命令我需要执行的操作(sudo/usr/sbin/service ) 命令必须包含 sudo
将脚本添加到 visudo+ 我的脚本中提到的所有命令中: Visudo 包含:
守护进程 ALL=NOPASSWD:/usr/bin/sudo、/path_my_script/script.sh
当然,脚本必须有打开规则,所以我更改了 755 的规则。
现在您可以尝试使用守护进程运行脚本,我使用以下命令:sudo -u daemon/patch_of_script/script.sh
最后一点是在 php 中添加命令:exec("sudo/path/./script.sh")
现在我可以通过 php 重新启动网络。 谢谢 BR MK
关于php - LINUX php服务重启不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40427298/