douxin20081125 2012-12-12 21:27 采纳率: 0%
浏览 325
已采纳

通过PHP的shell_exec()从网页执行bash脚本,这需要另一个用户的权限?

I have a couple of bash scripts on a Centos box which I use to do basic server admin stuff like restart services, etc. I run these as a standard user who is also the scripts' owner.

I tried to run these using shell_exec() in PHP, with the apache user, but it simply doesn't work - I'm guessing it doesn't have enough permissions (even with 775 and being in the correct group!) to run everything I want it to.

I've tried editing the sudoers file giving apache permission to run the script calls but it still doesn't work and has no error messages that I can see.

Any thoughts? How can one trigger a script from a web page which requires a different user to run?

  • 写回答

2条回答 默认 最新

  • duanchijie2323 2012-12-13 14:05
    关注
    1. check under which user is running apache ( for debian it is www-data)
    2. add www-data in sudoers list with permission to execute files that you like
    3. check which shell has www-data user in /etc/passwd (you will need to give valid shell)
    4. run script with /bin/bash -x (it will output for sure)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊