<div dir="ltr">I'm having a go at writing some PHP scripts to do simple things like view the status of VMs running on my Ubuntu KVM host.<div><br></div><div>I've installed php_libvirt_php but am failing at the first hurdle at the moment as I can't get the PHP script to connect.</div><div><br></div><div>My normal way of connecting virsh from the command line is like this:</div><div><br></div><div>$ virsh -c qemu+ssh://localhost/system<br></div><div>This asks for a password which is fine as I'm doing it from the command line. </div><div><br></div><div>I can't get a connection when I use other protocols:</div><div><div><br></div><div>$ virsh -c qemu+tcp://<a href="http://192.168.0.103/system">192.168.0.103/system</a></div><div>error: failed to connect to the hypervisor</div><div>error: unable to connect to server at '<a href="http://192.168.0.103:16509">192.168.0.103:16509</a>': Connection refused</div></div><div><br></div><div>I've tried using various $uri values for libvirt_connect but I get connection errors:</div><div><br></div><div><font color="#000000" face="Times New Roman" size="3">$uri="qemu+tcp://localhost/system";</font><br></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Connecting to libvirt (URI:qemu+tcp://localhost/system) </span><br style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Warning</b><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">: libvirt_connect(): unable to connect to server at 'localhost:16509': Connection refused in </span><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">/var/www/html/libvirt_test1.php</b><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> on line </span><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">8</b><br style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Libvirt last error: unable to connect to server at 'localhost:16509': Connection refused</span><font color="#000000" face="Times New Roman" size="3"><br></font></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><br></span></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">$uri="qemu://localhost/system";</span><br></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Connecting to libvirt (URI:qemu://localhost/system) </span><br style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Warning</b><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">: libvirt_connect(): Cannot read CA certificate '/etc/pki/CA/cacert.pem': No such file or directory in </span><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">/var/www/html/libvirt_test1.php</b><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> on line </span><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">8</b><br style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Libvirt last error: Cannot read CA certificate '/etc/pki/CA/cacert.pem': No such file or directory</span><font color="#000000" face="Times New Roman" size="3"><br></font></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><br></span></div><div><font color="#000000" face="Times New Roman" size="3">$uri="qemu+tcp://localhost/system";</font><br></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Connecting to libvirt (URI:qemu+tcp://localhost/system) </span><br style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Warning</b><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">: libvirt_connect(): unable to connect to server at 'localhost:16509': Connection refused in </span><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">/var/www/html/libvirt_test1.php</b><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> on line </span><b style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">8</b><br style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Libvirt last error: unable to connect to server at 'localhost:16509': Connection refused</span><font color="#000000" face="Times New Roman" size="3"><br></font></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><br></span></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><br></span></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Presumably the answer is to 1) either allow connections that don't require SSH, or 2) somehow allow a password-less SSH connection from the www-data user that's running the PHP script. 2) sounds like it might be very difficult, and I don't know how to do 1) as I've only ever connected this way with SSH. </span></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><br></span></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Can anyone please provide some advise on getting this working.</span></div></div>