如何在 PHP 中以特定用户身份运行外部命令 [英] How to run an external command as a specific user in PHP
本文介绍了如何在 PHP 中以特定用户身份运行外部命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想到了 suPHP 但这不是我需要的.以不同的用户身份运行整个 PHP 脚本不符合我的目的.我只需要以不同的用户身份运行一个 linux 命令行.
I thought of suPHP but that's not what I need. It doesn't serve to my purposes to run the whole PHP script as a different user. I just need to run one single linux command line as a different user.
有可能吗?
推荐答案
你可以试试 shell_exec 函数和须藤
You could try the shell_exec function and sudo
编辑:看到 sudo 提示输入密码,您可能想要使用 proc_open,它允许您使用管道.有关如何创建自定义密码管道的信息,请参阅此评论.
edit: seeing as sudo prompts for a password, you'd might wanna use proc_open, which allows you to use pipes. See this comment for how to create a custom password pipe.
这篇关于如何在 PHP 中以特定用户身份运行外部命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文