dongshike7171 2019-02-27 23:30
浏览 80
已采纳

PHP shell_exec访问deb 9上的系统服务

I'm trying to access a deb system service with PHP shell_exec and I just can't get it working.

This is the command I am trying to run from a php script :

shell_exec('sudo service icecast2 stop');

But it's not working for two reasons..

1) I'm not sure if I'm granting the correct user permissions in /etc/sudoers ?

%www-data ALL=NOPASSWD: /sbin/???????

2) ??????? = I'm not sure where to point to in the /sbin to allow access to system services? I've tried a variety of things but as I'm not sure which part I'm getting wrong (possibly both) I haven't been able to get anything to work.

Any help appreciated ;)

  • 写回答

1条回答 默认 最新

  • doutong6814 2019-02-28 00:55
    关注

    On my Debian systems service is in /usr/sbin, not in /sbin. So it should be:

    %www-data ALL=NOPASSWD: /usr/sbin/service
    

    You should also use the full path in the shell_exec() command, as /usr/sbin might not be in the webserver's $PATH.

    shell_exec('sudo /usr/sbin/service icecast2 stop');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?