I have installed php-libvirt as well as all required packages (I tried the remi rpm and compiling).
I have setup my php file as follows:
<?php
print_r ( libvirt_version() );
echo '<br>';
$uri="qemu+tcp:///system";
$credentials=array(VIR_CRED_AUTHNAME=>"fred",VIR_CRED_PASSPHRASE=>"fred");
echo ("Connecting to libvirt (URI:$uri)<BR>");
$conn=libvirt_connect($uri,false,$credentials);
if ($conn==false)
{
echo ("Libvirt last error: ".libvirt_get_last_error()."<br>");
exit;
} else {
$hostname=libvirt_get_hostname($conn);
echo ("hostname:$hostname<br>");
?>
However when I load the page I get:
Array ( [libvirt.release] => 2 [libvirt.minor] => 10 [libvirt.major] => 0 [connector.version] => 0.4.8 [connector.major] => 0 [connector.minor] => 4 [connector.release] => 8 )
Connecting to libvirt (URI:qemu+tcp:///system)
Libvirt last error: unable to connect to server at 'localhost:16509': Permission denied
It works fine from the command line when I run
# virsh -c qemu+tcp:///system list Please enter your authentication name: fred Please enter your password: Id Name State ----------------------------------------------------
I have tried the command line from another server to make sure it would work remotely and it was fine.
I have tried fred@hostname and that didn't work. I have tried VIR_CRED_USERNAME and that also didn't work.
What could be the issue?
By default authentication mechanism for libvirtd TCP connection is SASL. Till now TCP connection is listening and now we have to configure SASL based authentication. Edit /etc/libvirt/libvirtd.conf, they are using auth_tcp = "none", but use auth_tcp = "sasl" if not done already. Now execute the following command.
In your case libvirtd is listening for a TCP connection, but some time we need to make some changes to make it listen on the given port. First link in the references will be useful for that.
References:
https://askubuntu.com/questions/423425/i-cant-use-libvirt-with-listen-tcp
http://libvirt.org/auth.html#ACL_server_username
https://www-01.ibm.com/support/knowledgecenter/linuxonibm/liabp/liabpkvmsecsrmsasl.htm