Yesterday we wrote about installing VirtualBox in CentOS 7 and managing it with phpVirtualBox tool on a headless CentOS 7 server. That tutorial was well received so we decided to write a similar one for Ubuntu 14.04.

If you want to reference the similar for CentOS 7, read click this link to go to the post.

This brief tutorial is going to show you how to install VirtualBox on a headless Ubuntu 14.04 server and manage it via a web browser using phpVirtualBox software.

When configured correctly, you won’t need to be physically connected to the Ubuntu server to manage virtual guests creation and deletion. You’ll be able to do it from a remote location via your web browser.

In order for this to work you’ll need Apache2, PHP and support modules along with phpVirtualBox packages. Carry out the setup on a Ubuntu box is much easier than on a CentOS 7 machine, that’s because of the firewall and SELinux applications that come pre-installed in CentOS.

When you’re ready, sign on to your Ubuntu machine and run the commands below to update it first. Before installing software in Ubuntu, it’s already a good thing to update.

Run the commands below to update Ubuntu.

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

After that, run the commands below to install required kernel-headers and kernel packages.

sudo apt-get install build-essential dkms

 

Next, run the commands below to create a separate VirtualBox repository file in Ubuntu.

sudo vi /etc/apt/sources.list.d/virtualbox.list

 

Then copy and paste the below line in the file and save it.

deb http://download.virtualbox.org/virtualbox/debian trusty contrib

 

Next, run the commands below to download the repository key and install.

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

 

Finally, run the commands below to install VirtualBox

sudo apt-get update && sudo apt-get install VirtualBox-4.3

 

Nex,t run the commands below to download VirtualBox extension pack. This pack allows VirtualBox to function smoothly and interact with the host computer properly.

cd /tmp/ &&  wget http://download.virtualbox.org/virtualbox/4.3.12/Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack

 

Next, run the commands below to install the extension pack.

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack

 

After installing VirtualBox, go and create a dedicated user to manage VirtualBox connections. To do that, run the commands below to create a username called richard, a password for richard account and add the user to VirtualBox users group.

sudo useradd richard
sudo passwd richard
sudo usermod -aG vboxusers richard

After that, run the commands below to test if VirtualBox was correctly installed and loaded. To do that, run the commands below.

sudo /etc/init.d/vboxdrv status

 

If it’s not correctly installed, run the commands below to re load the kernel modules

sudo /etc/init.d/vboxdrv setup

 

  • Installing Apache2, PHP and PHP Modules

After installing and configuring VirtualBox, let’s go and install Apache2 and PHP and its modules. To do that, run the commands below.

sudo apt-get install apache2 php5 php5-common php-soap php5-gd

 

  • Installing phpVirtualBox in Ubuntu 14.04

Now that VirtualBox, Apache2 and PHP are installed, lets’ go and download phpVirtualBox package. To do that, run the commands below.

cd /tmp/ &&  wget http://sourceforge.net/projects/phpvirtualbox/files/phpvirtualbox-4.3-1.zip

 

Next, run the commands below to unzip the downloaded package

unzip phpvirtualbox*.zip

 

Next, create a root directory for phpVirtualBox.

sudo mv phpvirtualbox-4.3-1 /var/www/html/phpvirtualbox

 

Now copy the sample config file and rename it by running the commands below.

sudo cp /var/www/html/phpvirtualbox/config.php-example /var/www/html/phpvirtualbox/config.php

 

Then edit the configuration and add the user account and password you created earlier.

sudo vi /var/www/html/phpvirtualbox/config.php

 

Add the info for the user
[...]
var $username = 'richard';
var $password = 'my_password';
[...]

Next, create a new VirtualBox file and enter the info for the user as shown below.

sudo vi /etc/default/virtualbox

 

Then enter the info for the user and save the file.

VBOXWEB_USER=richard

 

Start VirtualBox web service by running the commands below.

sudo /etc/init.d/vboxweb-service start

 

Open your favorite web browser and connect to the server. You’ll be prompted with a logon page.  The username and password are admin

username: admin

password: admin

 

phpvirtualbox setup on ubuntu

 

Logon and start creating guest operating systems.

 

phpvirtualbox on ubuntu

 

At the end, I ran into trouble using the new user info created above. I had to switch to my Ubuntu user account to get vboxweb-service started.

 

Enjoy!