【问题标题】:LINUX php service restart not workLINUX php服务重启不起作用
【发布时间】:2016-11-04 16:15:24
【问题描述】:

我需要帮助,我有在 php 中运行此部分的 web 界面:

  $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 有关于接口的所有信息(但所有信息都没有关闭,所以上面的消息不能正常工作(这个服务仍然运行))

此脚本通过守护用户运行。

这是我的 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: /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 并将其添加到 VISUDO 中。我的脚本: sudo /usr/sbin/service network stop 进入 visudo 我必须添加所有已创建脚本的补丁并使用 sudo exect(''sudo /path/./script.sh" ) 的 php 调用脚本进行此更改后一切正常.

标签: php linux permissions debian visudo


【解决方案1】:

解决方案:

  1. 使用 rolus 为 root (root:root) 创建 sctipt 并命令我需要执行的操作 (sudo /usr/sbin/service) 命令必须包含 sudo

  2. 将脚本添加到 visudo+ 我的脚本中所指的所有命令: Visudo 包含:

    守护进程 ALL=NOPASSWD: /usr/bin/sudo, /path_my_script/script.sh

  3. 诅咒脚本必须有打开规则,所以我更改了 755 的规则。

  4. 现在你可以尝试用守护进程运行脚本,我使用这个命令:sudo -u daemon /patch_of_script/script.sh

  5. 最后一点是在 php 中添加命令:exect("sudo /path/./script.sh")

    现在我可以通过 php 重新启动网络。 谢谢 BR MK

【讨论】:

    【解决方案2】:

    exac($cmd, $mes); 替换为exec($cmd, $mes);

    【讨论】:

      猜你喜欢
      • 2012-06-05
      • 2012-01-25
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 2021-05-17
      • 2013-11-20
      • 2016-11-14
      • 1970-01-01
      相关资源
      最近更新 更多