dongou3286
2014-12-13 23:48 阅读 81
已采纳

如何使用nginx,php-fpm和Arch Linux从exec函数sudo

I can log in as any user and sudo whoami without password and get "root". When i try this with php -r 'echo exec("sudo whoami");' it works regardless of what user i am. But when i run this through the webserver (nginx) i get nothing. What gives?

ps xau | grep php

root 207 0.0 2.6 19876 4992 ? Ss 23:16 0:00 php-fpm: master process (/etc/php/php-fpm.conf) http 228 0.0 1.6 19876 3152 ? S 23:16 0:00 php-fpm: pool www http 229 0.0 1.6 19876 3144 ? S 23:16 0:00 php-fpm: pool www root 326 0.0 0.3 2504 692 pts/0 S+ 23:59 0:00 grep php

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongzhaoshi8497 dongzhaoshi8497 2014-12-14 01:28

    I appended 2>&1 to my command to see errors and it said "sudo: command not found".

    I then added putenv('PATH=' . getenv('PATH') . ':/usr/sbin'); to my php script and it worked.

    点赞 评论 复制链接分享

相关推荐