简体   繁体   English

如何使用php代码执行sudo命令?

[英]How to execute a sudo command with php code ?

I am executing a SUDO command in PHP script, 我正在用PHP脚本执行SUDO命令,

$username = 'tester';
$password = 'testerspassword';
$node = 'localhost';
exec('sudo /usr/sbin/ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);

When i am trying with putty and executing same as 当我尝试使用腻子并执行与

sudo ejabberdctl register testuser1 localhost pass123

Its working , but through PHP script its not working. 它可以工作,但是通过PHP脚本不能工作。 How to execute it through PHP script,If required to include .ppk file and username for verification then how to use it ? 如何通过PHP脚本执行它,如果要求包含.ppk文件和用户名进行验证,那么如何使用它?

Thanks in advanced! 提前致谢!

PHP is executed under the user account of Apache. PHP是在Apache的用户帐户下执行的。

You should add this user(usually called www-data, apache or similar) to /etc/sudoer ... 您应该将此用户(通常称为www-data,apache或类似用户)添加到/etc/sudoer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM