How to register user ejabberd with php?

I found code from the stack to execute the register command in the ejabberd xmpp chat server using php. ( Create user ejabberd with PHP )

I also add the line "www-data ALL = NOPASSWD: / usr / sbin / ejabberdctl" in the "/ etc / sudoers" file in ubuntu linux server 12.0

But when I run the file, I got the error:

"read_passphrase: cannot open / dev / tty: no such device or address. Host key verification failed.

In php code I am using the following:

`<?php
$username = 'tester';
$password = 'testerspassword';
$node = 'myserver.com';
exec('sudo /usr/sbin/ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);
if($output == 0)
{
    // Success!
}
else
{
    // Failure, $output has the details
    echo '<pre>';
    foreach($output as $o)
    {
        echo $o."\n";
    }
    echo '</pre>';
}
?>`

      

Please help me!

thank

+3


source to share


1 answer


Hi The following code works for me.

Just change one line above the code



exec('sudo -u ejabberd ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);

0


source







All Articles