The PHP libvirt extension, known as libvirt-php, adds the ability to managelibvirt virtualization directly from your PHP scripts.
The libvirt-php extension supports PHP 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, and 7.4.
To install this extension on Ubuntu 16.04 or 18.04, SSH in to your server as root and run the following commands one at a time.
sudo apt-get -y install gcc make autoconf libc-dev pkg-config sudo apt-get -y install libvirt-dev libxml2-dev xsltproc libxml2-utils wget http://libvirt.org/sources/php/libvirt-php-0.5.4.tar.gz tar xzf libvirt-php-0.5.4.tar.gz cd libvirt-php-0.5.4 PATH=/opt/sp/phpX.Y/bin:$PATH ./configure make sudo make install sudo bash -c "echo extension=libvirt-php.so > /etc/phpX.Y-sp/conf.d/libvirt-php.ini" sudo service phpX.Y-fpm-sp restart
To install this extension on Ubuntu 14.04 or 12.04, SSH in to your server as root and run the following commands one at a time.
sudo apt-get -y install gcc make autoconf libc-dev pkg-config sudo apt-get -y install libvirt-dev libxml2-dev xsltproc libxml2-utils wget http://libvirt.org/sources/php/libvirt-php-0.4.8.tar.gz tar xzf libvirt-php-0.4.8.tar.gz cd libvirt-php-0.4.8 PATH=/opt/sp/phpX.Y/bin:$PATH ./configure make sudo make install sudo bash -c "echo extension=libvirt-php.so > /etc/phpX.Y-sp/conf.d/libvirt-php.ini" sudo service phpX.Y-fpm-sp restart
You can verify libvirt-php is installed correctly by running this command:
phpX.Y-sp -i | grep -i libvirt
You should see the following output:
/etc/php7.0-sp/conf.d/libvirt-php.ini, libvirt Libvirt support => enabled Libvirt version => 1.3.1
To uninstall this extension, as root run the command:
sudo rm /etc/phpX.Y-sp/conf.d/libvirt-php.ini
Next, restart PHP-FPM with the command:
sudo service phpX.Y-fpm-sp restart