1. Go to this page and download the library: Download the-basement/libvirt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
the-basement / libvirt example snippets
// This assumes you have an ubuntu server image available from your KVM host
// This also assumes the default image location of the disks created by KVM.
// Both of these can be changed; disks that exist will not be overwritten
// disks that don't exist will be created.
$service = new TheBasement\Libvirt\LibvirtService();
$service->createServer([
'name' => 'my-virtual-machine',
'memory' => (string) (1024 * 1024), // 1G in KiB
'cores' => 1,
'threads' => 1,
'iso_path' => '/var/lib/libvirt/iso/ubuntu-22.04.4-live-server-amd64.iso',
'storage_pool' => 'default',
'network_mac' => '',
'video_ram' => '65536', // bytes of video ram
'disk_path' => '/var/lib/libvirt/images/ubuntu22.04-2.qcow2',
'disk_name' => 'ubuntu22.04-2.qcow2',
'disk_capacity' => 10 * 1024 * 1024 * 1024, // 10 GB in bytes
]);
// Gets all servers defined for the KVM
$servers = $service->findAllServers();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.