← ServerPilot Docs

How to Install the PHP libvirt Extension

In the examples shown, replace "X.Y" with your app's PHP version (for example, "5.6" or "7.0").

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.

Installing libvirt-php on Ubuntu 16.04 or 18.04

Current versions of libvirt-php require the PHP imagick extension. Before following the instructions to install libvirt-php below, you must first install the PHP imagick extension for the same version of PHP on which you're installing libvert-php.

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

Installing libvirt-php on Ubuntu 14.04 or 12.04

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

Verifying the Installation

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

Uninstalling the libvirt Extension

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
Last updated: October 8, 2018

Launch your first site in 5 minutes