donglei_0507 2016-01-26 12:12
浏览 71
已采纳

运行需要通过PHP进行root访问的程序

I'm searching to execute a program via PHP, but it needs roots access, because it's accessing hardware stuff.

Is it possible to allow the www-data user to execute some programs and access some devices ?

Is it really not safe to add www-data in sudo group ?

  • 写回答

1条回答 默认 最新

  • dongyu1918 2016-01-26 13:01
    关注

    I think changing script owner to www-data will make your script executable.

    In Linux, use chown to change script owner

    chown www-data file.txt
    

    This will change file.txt owner to www-data

    chown -R www-data /files/work
    

    Recursively grant ownership of the directory /files/work, and all files and subdirectories, to user www-data.

    Linux chown command details

    In PHP, you can use chown function to change ownership

    <?php
    
    // File name and username to use
    $file_name= "foo.php";
    $path = "/home/sites/php.net/public_html/sandbox/" . $file_name ;
    $user_name = "root";
    
    // Set the user
    chown($path, $user_name);
    
    // Check the result
    $stat = stat($path);
    print_r(posix_getpwuid($stat['uid']));
    
    ?>
    

    Php chown details

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了