php-fpm:shell_exec无效执行某些脚本

发布于 2025-02-10 12:21:36 字数 609 浏览 0 评论 0原文

服务器:Debian 11,nginx,php8.1-fpm

我想从php执行此命令,但不起作用,当我从终端运行时(root)

$output = shell_exec('/usr/bin/dos2unix /var/www/script.sh');
echo $output;

运行下面的代码时,它可以正常工作,

$output = shell_exec('ls /usr/bin/');
echo $output;

我认为我认为运行该运行的用户脚本是 www-data 基于下面的代码,

 $linuxUser = posix_getpwuid(posix_getuid());
 echo $linuxUser['name'];
result is www-data

我在 visudo 中也添加了此内容,只是为了进行测试,但仍无法正常工作

www-data all = nopasswd:all

server: Debian 11, nginx, php8.1-fpm

i want to execute this command from php but is not working, when i run from terminal (root)it works

$output = shell_exec('/usr/bin/dos2unix /var/www/script.sh');
echo $output;

when i run the code below it works

$output = shell_exec('ls /usr/bin/');
echo $output;

i think the user that run the script is www-data based on the code below

 $linuxUser = posix_getpwuid(posix_getuid());
 echo $linuxUser['name'];
result is www-data

also i added this in visudo just to test but still not working

www-data ALL=NOPASSWD: ALL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖伴 2025-02-17 12:21:36

Visudo
当您粘贴时,

www-data ALL=(ALL) NOPASSWD:ALL

请确保它位于最底层或将无法工作,因此请在文件末端移动该线路

in visudo
when u paste this

www-data ALL=(ALL) NOPASSWD:ALL

make sure it is at the very bottom line or it will not work, so move that line at the end of the file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文