Virtual Machines make life easier. In development they allow you to create completely destructible instances of machines within a few moments, giving you a safe place to execute that new code you’ve written or try out that new software package you’ve been reading lots about. Although Virtual Machines most certainly do have their place in Production enviroments, they don’t usually appear in small scale situations – from my experience.
Ever since I started “hacking” (messing with stuff, not breaking into stuff) I’ve always loved the concept of Virtual Machines, running an OS within my OS just seemed crazy, but I’ve always found it a burden to have to use clunky UI to manage them. My favourite of all of the Virtual Machines/Hypervisors has always been Virtualbox, with the main reason behind it being that it’s free and open source. As the years have passed, I’ve found myself administrating my Linux servers without any form of Desktop UI and simply through CLI, yet I never found a way to feed my hunger for Virtual Machines from a Terminal. That is until I discovered that VirtualBox can be easily managed from the CLI tools it comes with & phpvirtualbox.
This guide will show you how to set up a neat headless (no Desktop GUI) environment for running VM’s:
Requirements:
- A Linux Server – This guide will assume you’re running Ubuntu
- Apache/Nginx/Lighttpd
- PHP 5.*
VirtualBox
First of all we need to install VirtualBox, preferably the latest version you can get hold of. If you’re repo’s don’t have a version close to 4.1.8 (latest at the time of writing this) grab a copy from the VirtualBox site. If you can’t tell which version is in the repo’s then I’d install the VirtualBox repos on the previously mentioned page (there’s a guide too). Once we’re ready, install:
sudo apt-get install virtualbox-4.1
After a few minutes (1.5Mb adsl connections means a fair few minutes for me) we are ready to go. From this point, you can manage Virtual Machines via two commands:
vboxmanage vboxheadless
Next, I like to create a user to run Vbox, so I create a user called “vbox” and add it to the “vboxusers” group:
useradd -a vbox -g vboxusers
After which provide the credentials you’re asked for, yada yada yada.
phpVirtualBox
phpVirtualBox is a light-weight web interface for VirtualBox written in PHP (duh). It was designed to replicate the interface of VirtualBox, so things should look vaguely familiar. VirtualBox will have installed a service called “vboxweb-service”, this service provides XML data which can be used to read and modify your VM’s settings, make sure this service is running.
Get phpVirtualBox from here project’s home page and un-package it somewhere where your web server can get to it.
Within the folder you’ve extracted will be a file called ‘config.php-example’, open this file up via any text editor and look for the two lines where $username and $password are defined. These two values need to be the same as the vbox user’s details, so enter these in and save the file as config.php.
That should be it, navigate your web browser to the directory where you saved phpVirtualBox and login using “admin” x2. You can change the login details from the “File” menu once logged in.
Optional: Virtualbox Extension Pack
Although not needed, it may be useful for you to extend Virtualbox’s functionality with Oracle’s optional package, this package provides you with several pieces of functionality, must useful being USB2 support and RDP.
Grab the package from Virtualbox’s website here and store it somewhere near by. Once you’ve done so, run this command from cli:
sudo vboxmanage extpack install "file location for extpack"
And that’s it, that’s as far as this guide goes. As for using the phpVirtualbox interface as well as any errors you encounter, you’re on your own!

