如何在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屋!
查看全文