original help from http://nerdoftherings.net/wp/?p=90

Using Ubuntu Server 10.10 (“Maverick Meerkat”)

1) Install the system (select options a. LAMP b.OpenSSH c.Samba)

2) Create a user named “vbox” as your main user to follow this example

Type the following in a “putty” shell so you can copy and paste and you don’t have to type these out

sudo sh -c ‘echo deb http://download.virtualbox.org/virtualbox/debian maverick non-free >> /etc/apt/sources.list’
sudo apt-get update (you will get a key verification error, so then put the line below)
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add –
sudo apt-get update
sudo apt-get install virtualbox-3.2 (hit Y when asked if you want to download the 50mb)


Install PhpVirtualBox0.5

cd /var/www
sudo wget http://phpvirtualbox.googlecode.com/files/phpvirtualbox-0.5.zip
sudo chmod +x vboxwebsrv
sudo nano vboxwebsrv

Now we can have this start on boot:

sudo update-rc.d vboxwebsrv defaults

if you do not have unzip installed then install it now:

sudo apt-get install unzip
sudo unzip phpvirtualbox-0.5.zip
sudo rm -rf phpvirtualbox-0.5.zip

Open the config.php file in the phpvirtualbox-0.5 directory:

cd phpvirtualbox-0.5
sudo nano config.php

Change the following to match your setup:

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

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

vboxwebsrv -b -p 18083 -H localhost

You should now be able to access virtualbox via your browser by typing in: (replace’ hostname’ with the ip or hostname of the computer you just setup)

http://hostname/phpvirtualbox-0.5/

Make it more secure and start up on it’s own:

cd /etc/init.d
sudo wget http://phpvirtualbox.googlecode.com/files/vboxwebsrv

Now open the file to edit some information:

sudo chmod +x vboxwebsrv
sudo nano vboxwebsrv

Change the following to match your installation:

USER=vbox

Change the following line

su ${USER} -c ‘vboxwebsrv -b –logfile /dev/null >/dev/null

Now we can have this start on boot:

sudo update-rc.d vboxwebsrv defaults

sudo touch /var/www/phpvirtualbox-0.5/.htaccess

sudo nano /var/www/phpvirtualbox-0.5/.htaccess

Add the following into the file

AuthUserFile /home/vbox/.htpasswd

AuthGroupFile /dev/null

AuthName “Login to phpVirtualBox”

AuthType Basic

<Limit GET POST>

require valid-user

</Limit>

htpasswd -c /home/vbox/.htpasswd vbox

Now we should reboot the server and make sure that everything is working.

sudo shutdown -r now

Auto Startup and Shutdown of Virtual Machines

cd /etc/init.d

sudo nano /vboxcontrol.sh

insert the text below into the file


#!/bin/sh

# vboxcontrol Startup script for VirtualBox 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

#

# Version 20090301 by Kevin Swanson based 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=”vboxuser”

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`

# Copyright is 4 lines

if [ $RUNNING_MACHINES != 4 ]; 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 vrdp”

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 acpipowerbutton”

$SU “$VBOXMANAGE controlvm $VM acpipowerbutton”

done

rm -f /var/lock/subsys/vboxcontrol

wait_for_closing_machines

;;

start-vm)

log_action_msg “Starting VM: $2 …”

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

;;

stop-vm)

log_action_msg “Stopping VM: $2 …”

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

;;

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 |stop-vm |poweroff-vm }”

exit 3

esac

exit 0


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 machines_enabled

Enter names of machines you want to start and stop in the file

sudo apt-get install acpid acpi-support