Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Could you tell me how to create a new domain?
From PHP API Reference guide:
I have seen these functions:

(i)   libvirt_image_create($conn, $name, $size, $format)
(ii)   libvirt_domain_new($conn, $name, $arch, $memMB, $maxmemMB, $vcpus, $iso_image, $disks, $networks, $flags)
(iii) libvirt_domain_create($res)
(iv)  libvirt_domain_create_xml($conn, $xml)

The problem I am facing is that i dont know the steps to create a new domain. Either I have to create a new image first using libvirt_image_create .... or something else.

share|improve this question

Hi I'll comment on this as I'm the developer and maintainer of libvirt-php.

libvirt_image_create($conn, $name, $size, $format)

This API is only for creation of the virtual machine image (the virtual disk for the virtual machine). It doesn't do kind of domain (virtual machine) creation. You don't need it if you use PXE/network boot and similar.

libvirt_domain_new($conn, $name, $arch, $memMB, $maxmemMB, $vcpus,
    $iso_image, $disks, $networks, $flags)

This is for installation of the new virtual machine. First of all, you need to connect to libvirt daemon instance using libvirt_connect(). The return value of libvirt_connect() is the pointer/resource you need to pass as the first argument of this function. Then, you have to provide a virtual machine name, architecture (i686 or x86_64), initial and maximum memory in Megabytes (see the system specifications for operating system you want to install there first), number of VCPUs, ISO image to install this from (for PXE boot you don't require this and you can pass 'false' there), array of disk information (may be false too) and network cards.

The flags are optional and you don't have to pass them. Please refer to examples directory of the libvirt-php installation for real-world example - this is better than something written in here. Installation itself is a complex task so that's why it requires too many information


This creates the domain identified by a resource. The resource is basically already existing domain found by libvirt_domain_lookup_*() API functions.

libvirt_domain_create_xml($conn, $xml)

This creates one time domain that's not persistent. This domain is just run once as based on the libvirt XML file.

For format of libvirt XML files please refer to libvirt documentation, not libvirt-php.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.