Skip to content

Instantly share code, notes, and snippets.

@kirasglimmer
Last active September 29, 2017 22:27
Show Gist options
  • Save kirasglimmer/171f387a633cee7c24aa to your computer and use it in GitHub Desktop.
Save kirasglimmer/171f387a633cee7c24aa to your computer and use it in GitHub Desktop.
How to install VirtualBoxPHP on Ubuntu Server 14.04

Instructions adapted from: https://www.liberiangeek.net/2014/09/install-virtualbox-headless-ubuntu-14-04-server-manage-phpvirtualbox/ http://linuxhomeserverguide.com/server-config/phpVirtualBox.php

start with:

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

install dkms:

sudo apt-get install build-essential dkms

Edit:

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

and add:

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

Add the key:

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

Install VirtualBox:

sudo apt-get update && sudo apt-get install virtualbox-5.1 virtualbox-ext-pack virtualbox-dkms

Create a user that will own/run the phpVirtualBox:

sudo useradd vboxadmin
sudo passwd vboxadmin
sudo usermod -aG vboxusers vboxadmin

Make sure user has home directory:

sudo mkdir /home/vboxadmin && sudo chown vboxadmin:users /home/vboxadmin && sudo usermod  --home /home/vboxadmin vboxadmin

... and is part of sudoers:

sudo adduser vboxadmin sudo

#Important: Login as this user now!!!

Install the service and configure it for use by vboxadmin:

sudo systemctl enable vboxweb-service

Set up the /lib/systemd/system/vboxweb.service file. Add/update the following entries in the [Service] section:

User=vboxadmin
Group=vboxusers
ExecStart=/usr/bin/vboxwebsrv --host=127.0.0.1 --pidfile /home/vboxadmin/.vboxweb.pid  --background
PIDFile=/home/vboxadmin/.vboxweb.pid

Change the VirtualBox web auth library setting:

vboxmanage setproperty websrvauthlibrary null

Check VirtualBox status:

sudo service vboxweb status

Install apache and php:

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

Download phpVirtualBox:

cd /tmp/ &&  wget https://downloads.sourceforge.net/project/phpvirtualbox/phpvirtualbox-5.0-5.zip?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fphpvirtualbox%2Ffiles%2F&ts=1506652449&use_mirror=pilotfiber

Unzip phpVirtualBox:

unzip phpvirtualbox*.zip

Move the extracted files to the web server:

sudo mv phpvirtualbox-5.0.5 /var/www/html/phpvirtualbox

Copy the default config file:

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

Edit the config file to add the user created earlier:

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

Change the username and password as appropriate:

var $username = 'vboxadmin';
var $password = 'xxxx';

Create the virtualbox file and edit it:

sudo vi /etc/default/virtualbox

Add these two lines (http://sourceforge.net/p/phpvirtualbox/wiki/vboxweb-service%20Configuration%20in%20Linux/):

VBOXWEB_USER=vboxadmin
VBOXWEB_HOST=127.0.0.1

Start VirtualBox:

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

Configure auto-start

On ubuntu server 14.04, set the service to autostart with a startup script in /etc/init/vboxwebsrv.conf

# vboxwebsrv - phpVirtualBox web server
#
description	"phpVirtualBox web server daemon"

start on runlevel [2345]
stop on runlevel [!2345]

expect fork
respawn

exec vboxwebsrv -b

Other tips

Download VirtualBox extension pack from: https://www.virtualbox.org/wiki/Downloads

Once installed, VBoxManage is pretty handy for configurations. For example, to resize a HDD:

VBoxManage modifyhd Win7.vdi --resize 262144

Configure 2D & 3D acceleration:

VBoxManage modifyvm {VM} --accelerate3d [on|off]
VBoxManage modifyvm {VM} --accelerate2dvideo [on|off]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment