0

From a php page I am trying to start Virtual Machine using virsh tool on KVM hypervisor but I am getting this error.

error: Failed to connect socket to '@/var/www/.libvirt/libvirt-sock': Connection refused
error: failed to connect to the hypervisor.

Please suggest some work around. Is it possible doing this without giving www-data user, root privilege?

Thanks

1

1 Answer 1

0

First Way

Php code

<?php $output=shell_exec("virsh -c qemu:///system start vmname 2>&1"); echo "<pre>$output</pre>"; ?>

Beside that run this command in terminal in Ubuntu 12.04 , can do same for other flavors.

sudo chown www-data /var/run/libvirt/libvirt-sock

Additionally you can use

sudo visudo www-data ALL = NOPASSWD: /usr/bin/virsh

Second Way

Use libvirt-php API to start the VM. To start VM use libvirt_domain_create function. See this for more information http://libvirt.org/php/api-reference.html#libvirt_domain_create

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .