This is assuming Ubuntu 11.04 64 bit

Edit the source list

sudo nano /etc/apt/sources.list

Add the following line

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

Save and exit the file

Add gpg key

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

sudo apt-get update

To make sure your kernel is updated properly with virtualbox:

sudo apt-get install dkms

wget http://download.virtualbox.org/virtualbox/4.0.8/virtualbox-4.0_4.0.8-71778~Ubuntu~natty_amd64.deb
sudo dpkg -i virtualbox-4.0_4.0.8-71778~Ubuntu~natty_amd64.deb

you will get dependency errors, so run the following to install the dependencies:

sudo apt-get -f install

sudo /etc/init.d/vboxdrv setup

Install the seperate extention pack

cd /tmp

wget http://download.virtualbox.org/virtualbox/4.0.8/Oracle_VM_VirtualBox_Extension_Pack-4.0.8-71778.vbox-extpack

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.0.8-71778.vbox-extpack

Add the user you want to the VirtualBox group (replace vbox with whoever you want as your USER)

sudo /usr/sbin/usermod -G vboxusers vbox

Install phpVirtualBox

wget http://phpvirtualbox.googlecode.com/files/phpvirtualbox-4.0-6.zip

If not already installed, install unzip now

sudo apt-get install unzip

Unzip phpVirtualBox

sudo unzip phpvirtualbox-4.0-6.zip -d /var/www/

Edit the settings

sudo mv /var/www/phpvirtualbox-4.0-6/ /var/www/phpvirtualbox/

cd /var/www/phpvirtualbox/

sudo nano config.php-example

Change the user & password to the one you used to install it with

var $username = ‘vbox’;
var $password = ‘pass’;

Press CTL+x and answer questions to save the file.

sudo cp config.php-example config.php

Run the following to see if you can connect to the virtualbox host


vboxwebsrv -b -p 18083 -H localhost --logfile /home/vbox/VboxLogfile.txt

Make vboxwebsrv server launch on boot by itself

cd /etc/init.d

sudo wget http://phpvirtualbox.googlecode.com/files/vboxwebsrv

Now open and edit the config

sudo chmod +x vboxwebsrv
sudo nano vboxwebsrv

Change the settings to match your user

USER=vbox

Press CTL+x and answer questions to save the file.

Make it start on boot:

sudo update-rc.d vboxwebsrv defaults

Reboot and make sure it works

sudo shutdown -r now

Auto Startup and Shutdown of Virtual Machines

cd /etc/init.d

sudo nano vboxcontrol.sh


Insert the following into the file:

#!/bin/sh

# vboxcontrol Startup script for VirtualBox 4.0 Virtual Machines

### BEGIN INIT INFO

# Provides: vboxcontrol

# Required-Start: vboxdrv

# Required-Stop: vboxdrv

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Description: VirtualBox VM Control

### END INIT INFO

#

# This version is Vbox4, v1.0 by David FuchsBased on:

# Version 20090301 by Kevin Swansonbased on:

# Version 2008051100 by Jochem Kossen

# http://farfewertoes.com

#

# Released in the public domain

#

# This file came with a README file containing the instructions on how

# to use this script.

#

# Source function library.

if [ -f /lib/lsb/init-functions ] ; then

. /lib/lsb/init-functions

elif [ -f /etc/rc.d/init.d/functions ] ; then

. /etc/rc.d/init.d/functions

elif [ -f /etc/rc.d/init.d/functions ] ; then

. /etc/rc.d/init.d/functions

else

echo “Unable to find default functions!”

exit 1

fi

################################################################################

# INITIAL CONFIGURATION

VBOXDIR=”/etc/virtualbox”

VM_USER=”vbox”

USE_NAT=”no”

export PATH=”${PATH:+$PATH:}/bin:/usr/bin:/usr/sbin:/sbin”

if [ -f $VBOXDIR/config ]; then

. $VBOXDIR/config

fi

SU=”su $VM_USER -c”

VBOXMANAGE=”VBoxManage ”

################################################################################

# FUNCTIONS

# Determine if USE_NAT is set to “yes”

use_nat() {

if [ “$USE_NAT” = “yes” ]; then

return `true`

else

return `false`

fi

}

log_failure_msg() {

echo $1

}

log_action_msg() {

echo $1

}

# Check for running machines every few seconds; return when all machines are

# down

wait_for_closing_machines() {

RUNNING_MACHINES=`$SU “$VBOXMANAGE list runningvms” | wc -l`

# >v4.0, no copyright…

if [ $RUNNING_MACHINES != 0 ]; then

sleep 5

wait_for_closing_machines

fi

}

################################################################################

# RUN

case “$1” in

start)

if [ -f /etc/virtualbox/machines_enabled ]; then

cat /etc/virtualbox/machines_enabled | while read VM; do

log_action_msg “Starting VM: $VM …”

$SU “$VBOXMANAGE startvm $VM -type headless”

RETVAL=$?

done

touch /var/lock/vboxcontrol

fi

;;

stop)

# NOTE: this stops all running VM’s. Not just the ones listed in the

# config

cat /etc/virtualbox/machines_enabled | while read VM; do

#$SU “$VBOXMANAGE list runningvms” | while read VM; do

log_action_msg “Shutting down VM: $VM …”

echo “$VBOXMANAGE controlvm $VM savestate”

$SU “$VBOXMANAGE controlvm $VM savestate”

done

rm -f /var/lock/subsys/vboxcontrol

wait_for_closing_machines

;;

start-vm)

log_action_msg “Starting VM: $2 …”

$SU “$VBOXMANAGE startvm “$2″ -type headless”

;;

stop-vm)

log_action_msg “Stopping VM: $2 …”

$SU “$VBOXMANAGE controlvm “$2″ savestate”

;;

poweroff-vm)

log_action_msg “Powering off VM: $2 …”

$SU “$VBOXMANAGE controlvm “$2″ poweroff”

;;

status)

echo “The following virtual machines are currently running:”

$SU “$VBOXMANAGE list runningvms” | while read VM; do

echo -n “$VM (”

echo -n `$SU “VBoxManage showvminfo ${VM%% *}|grep Name:|sed -e ‘s/^Name:s*//g'”`

echo ‘)’

done

;;

*)

echo “Usage: $0 {start|stop|status|start-vm

name>|stop-vm|poweroff-vm}”

exit 3

esac

exit 0

Ctrl-X and Y Enter to save

sudo chmod +x vboxcontrol.sh

sudo update-rc.d vboxcontrol.sh defaults 98 02

Create a directory called /etc/virtualbox/machines_enabled. This will contain a simple list of VMs. These are the machines that will be started and stopped by the script. BE CAREFUL! If a name is wrong, the machine will never be stopped and the script will hang. Furthermore, if other machines are running, the script will hang as it waits for all VMs to stop. This isn’t necessarily a “bad thing”, as you would not want the host to shutdown with VMs running.

sudo mkdir /etc/virtualbox/

sudo nano /etc/virtualbox/machines_enabled

Enter names of machines you want to start and stop in the file; include one VM name per line.

Install support for acpi power control on your host and VM’s

sudo apt-get install acpid acpi-support


Login and Try It Out!

from any browser navigate to your machine with the /phpvirtualbox directory (it http://192.168.1.210/phpvirtualbox)
login default is admin/admin