php-fpm:shell_exec无效执行某些脚本
服务器: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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Visudo 中
当您粘贴时,
请确保它位于最底层或将无法工作,因此请在文件末端移动该线路
in visudo
when u paste this
make sure it is at the very bottom line or it will not work, so move that line at the end of the file