Articles

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, and 7.2.

Installing libvirt-php on Ubuntu 16.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, 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

Last updated: August 31, 2017