Tag Archives: VirtualBox

VirtualBox and phpvirtualbox

Headless Virtualbox running on Ubuntu 12.04 server

http://www.howtoforge.com/phpvirtualbox-running-virtual-machines-with-virtualbox-4.2-and-phpvirtualbox-on-a-headless-ubuntu-12.04-server
http://www.howtoforge.com/vboxheadless-running-virtual-machines-with-virtualbox-4.1-on-a-headless-ubuntu-12.04-server
http://www.howtoforge.com/managing-a-headless-virtualbox-installation-with-phpvirtualbox-on-nginx-ubuntu-12.04

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

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

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -
apt-get update
apt-get install linux-headers-$(uname -r) build-essential virtualbox-4.3 dkms
wget http://download.virtualbox.org/virtualbox/4.3.10/Oracle_VM_VirtualBox_Extension_Pack-4.3.10-92957.vbox-extpack
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.10-92957.vbox-extpack
useradd -d /home/vbox -m vbox
passwd vbox
adduser vbox vboxusers

/etc/default/virtualbox

VBOXWEB_USER=vbox

update-rc.d vboxweb-service defaults

phpvirtualbox in Nginx

apt-get install nginx php5-common php5-mysql php5-suhosin php5-fpm php-pear wget

/etc/nginx/sites-available/virtualbox.conf

server {
    listen 80;
    server_name virtualbox.example.org;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name virtualbox.example.org;
    client_max_body_size 15M;

    ssl on;
    ssl_certificate /etc/ssl/private/example_org.crt;
    ssl_certificate_key /etc/ssl/private/example_org.key;

    ssl_session_timeout 5m;

    ssl_protocols SSLv3 TLSv1;
    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    ssl_prefer_server_ciphers on;

    root /usr/share/nginx/www/phpvirtualbox;
    index index.php index.html index.htm;

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    location ~ /\.ht {
            deny all;
    }

    access_log /var/log/nginx/virtualbox/access.log;
    error_log  /var/log/nginx/virtualbox/error.log;

}

cd /usr/share/nginx/www
wget http://downloads.sourceforge.net/project/phpvirtualbox/phpvirtualbox-4.3-1.zip
unzip phpvirtualbox-4.3-1.zip
mv phpvirtualbox-4.3-1 phpvirtualbox
cd /usr/share/nginx/www/phpvirtualbox/
cp config.php-example config.php

/usr/share/nginx/www/phpvirtualbox/config.php

var $username = 'vbox';
var $password = 'the password you used when you created vbox user';

cd /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/virtualbox.conf /etc/nginx/sites-enabled/virtualbox.conf 
nginx -t
service nginx reload

Login to phpVirtualbox
https://virtualbox.example.org/

user: admin
default password: admin
new password: pick your own

Create VM from command line

VBoxManage --help

Create an Ubuntu 12.04 Server VM with 512MB memory and a 10GB hard drive from the Ubuntu 12.04 Server iso image:

$ VBoxManage createvm --name "Ubuntu 12.04 Server" --register
$ VBoxManage modifyvm "Ubuntu 12.04 Server" --memory 512 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0
$ VBoxManage createhd --filename Ubuntu_12_04_Server.vdi --size 10000
$ VBoxManage storagectl "Ubuntu 12.04 Server" --name "IDE Controller" --add ide
$ VBoxManage storageattach "Ubuntu 12.04 Server" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium Ubuntu_12_04_Server.vdi
$ VBoxManage storageattach "Ubuntu 12.04 Server" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /home/ubuntu-12.04-server-amd64.iso

Importing an existing VM
VBoxManage registervm Machines/examplevm/examplevm.xml

Starting a VM with VBoxHeadless
VBoxHeadless --startvm "Ubuntu 12.04 Server"

Stop a VM
VBoxManage controlvm "Ubuntu 12.04 Server" poweroff

Pause a VM
VBoxManage controlvm "Ubuntu 12.04 Server" pause

Reset a VM
VBoxManage controlvm "Ubuntu 12.04 Server" reset