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 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?
  • ¥15 C#连接不上服务器,