phpvirtualbox - Running Virtual Machines With VirtualBox 4.2 and phpvirtualbox On A Headless Ubuntu 12.04 Server

Author: Luis Rodriguez<luis [at] techreanimate[dot] com>

phpvirtualbox is a web-based VirtualBox front-end written in PHP that allows you to access and control remote VirtualBox instances. It tries to resemble the VirtualBox GUI as much as possible to make work with it as easy as possible. It is a nice replacement for the VirtualBox GUI if you run VirtualBox in headless servers. This tutorial explains how to install phpvirtualbox on an Ubuntu 12.04 server to manage a locally installed, headless VirtualBox (version 4.2).

 

1 Preliminary Note

I have tested this on an Ubuntu 12.04 server (host system) with the IP address 192.168.0.100 where I'm logged in as root.

Run:

sudo su

 

2 Installing VirtualBox

To install VirtualBox 4.2 on our Ubuntu 12.04 server, we open /etc/apt/sources.list...

nano /etc/apt/sources.list

... and add the following line to it:

[...]
deb http://download.virtualbox.org/virtualbox/debian precise contrib

Then we download the VirtualBox public key...

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -

... and update our package database:

apt-get update

Afterwards, we install VirtualBox 4.2 as follows:

apt-get install linux-headers-$(uname -r) build-essential virtualbox-4.2 dkms

(The dkms package ensures that the VirtualBox host kernel modules are properly updated if the Linux kernel version changes.)

Starting with version 4.0, VirtualBox has introduced so called "extension packs" and has outsourced some functionality like remote desktop connection support (VRDP) that was part of VirtualBox packages before version 4.0 into these extension packs. Because we need remote desktop connections to control our virtual machines, we need to install the appropriate extension pack now. Go to http://www.virtualbox.org/wiki/Downloads, and you will find a link to the following extension pack:

VirtualBox 4.1.18 Oracle VM VirtualBox Extension Pack
Support for USB 2.0 devices, VirtualBox RDP and PXE boot for Intel cards.

Download and install the extension pack as follows:

cd /tmp
wget http://download.virtualbox.org/virtualbox/4.2.12/Oracle_VM_VirtualBox_Extension_Pack-4.2.12-84980.vbox-extpack
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.11-84980.vbox-extpack

(Make sure you grab the latest version from the VirtualBox web site.)

Now we must add the user that will run VirtualBox with password set(vbox in this example) to the vboxusers group:

useradd –d /home/vbox –m vbox

passwd vbox

Type yourpassword twice.

adduser vbox vboxusers

Edit/create virtualbox conf and let's add this user:

nano /etc/default/virtualbox

[...]
VBOXWEB_USER=vbox

Now let’s just make sure the service is in startup:

update-rc.d vboxweb-service defaults

/etc/init.d/vboxweb-service start

Install Apache:

apt-get install apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common apache2 apache2-doc apache2-suexec libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libapr1 php5-common php5-mysql php-pear wget

Download and copy over phpvirtualbox:

cd /tmp
wget https://phpvirtualbox.googlecode.com/files/phpvirtualbox-4.2-4.zip

unzip phpvirtualbox-4.2-4.zip

cp phpvirtualbox-4.2-4 /var/www/phpvirtualbox/

Edit php phpvirtualbox conf file and add the user and password:

nano /var/www/phpvirtualbox/config.php
[...]
var $username = 'vbox';
var $password = 'your vbox password';

Now you can access phpvirtualbox at http://192.168.0.100/phpvirtualbox

This guide was made using https://www.howtoforge.com/vboxheadless-running-virtual-machines-with-virtualbox-4.1-on-a-headless-ubuntu-12.04-server

Share this page:

Suggested articles

11 Comment(s)

Add comment

Comments

By: Gerrit

When I created the /var/www/phpvirtualbox/config.php with your information I got an AJAX error (couldn't parse it).

 It would be better to update the file /var/www/phpvirtualbox/config.php-example with the username and password, and then save it as the config.php file.

But other than that, it worked great! Thanks.

By: Bas

Thanks to Gerrit it works fine.

The only problem I have is that I can not login with the vbox user only with admin.

By: Anonymous

The vbox user only runs vboxweb-service and is used for the SOAP interaction. To create another user for phpvirtualbox, use the admin panel within the application.

By: Anonymous

Hi,

 

I'm confused 

I installed everything, and with some update weblinks (virtualbox 4.3 and  Oracle_VM_VirtualBox_Extension_Pack-4.3.2-90405.vbox-extpack) I think I've got virtualbox up and running.

I can't however login to the phpvirtualbox site. password setting via the  passwd vbox command is set to 'test', also the password in config.php is test, but still I get "Invalid username or password."

 

Where did my thoughts go in the wrong direction???

By: Gordon

The source files for phpvirtualbox have moved from  Googlecode to Sourceforge. The latest version is located at http://sourceforge.net/projects/phpvirtualbox/

 

By: Anonymous

I think there is a syntax error in the copy command

 cp phpvirtualbox-4.2-4 /var/www/phpvirtualbox/

By:

First of all a nice tutorial. I found a few small mistakes, however which could be fixed. VirtualBox 4.1.18 Oracle VM VirtualBox Extension Pack ---- speaking about the current version. Support for USB 2.0 devices, VirtualBox RDP and PXE boot for Intel cards. Download and install the extension pack as follows: cd /tmp wget http://download.virtualbox.org/virtualbox/4.2.12/Oracle_VM_VirtualBox_Extension_Pack-4.2.12-84980.vbox-extpack ---- speaking about 4.2.12 VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.11-84980.vbox-extpack ---- speaking about 4.2.11 It should be : ---------------------------------------------------------------------- cd /tmp wget http://download.virtualbox.org/virtualbox/4.2.18/Oracle_VM_VirtualBox_Extension_Pack-4.2.18.vbox-extpack VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.18.vbox-extpack

By: Anonymous

If running this on an Ubuntu 12.04 minimal install, unzip is not installed and should be added to the list of packages to retrieve via apt-get while pulling down apache. Also, wget is listed as part of the package list to get with apache, yet is already called for use in step 2 to obtain the repo key.

By: Shane G

I have attempted this setup more than once with less than successful results.  I can hit the server, but the instance of PHPVB is says the site is not found. 

What am I missing? (Aside from experience) :D

 

By: Shane G

I found my error... 

Mods - please delete :) 

 

By: Anonymous

Configured everything as per the tutorial. When trying to log in to phpvirtualbox with the username and password provided in config.php I get "Invalid username or password"

 Am I supposed to log in using some other login credentials?

 The server appears to be running:

netstat -plnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1071/mysqld    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1241/apache2   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      947/sshd       
tcp        0      0 127.0.0.1:18083         0.0.0.0:*               LISTEN      1164/vboxwebsrv
tcp6       0      0 :::22                   :::*                    LISTEN      947/sshd