VirtualBox admin using phpvirtualbox

1 Add a vbox user
sudo adduser vbox
Now we must add the user to the vboxusers group:
sudo adduser vbox vboxusers

2 Start VirtualBox Web Services
Create the file /etc/default/virtualbox and put the line VBOXWEB_USER=vbox in it (so that the VirtualBox SOAP API which is called vboxwebsrv runs as the user vbox):

echo '# virtualbox defaults file' | sudo tee /etc/default/virtualbox
echo 'VBOXWEB_USER=vbox' | sudo tee -a /etc/default/virtualbox

Next create the system startup links for vboxwebsrv and start it:
sudo systemctl enable vboxweb-service
sudo systemctl start vboxweb-service

3 Install Apache2
We need a web server with PHP support to serve phpVirtualBox. Install Apache and PHP as follows:
sudo apt-get -y install apache2 libapache2-mod-php7.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libapr1 php7.0-common php7.0-mysql php7.0-soap php-pear wget

Restart Apache:
sudo systemctl restart apache2.service

4 Download and install phpvirtualbox
I want to serve phpVirtualBox from Apache’s default virtual host with the document root /var/www/html (I will install it in /var/www/html/phpvirtualbox):
cd /var/www/html

sudo wget http://downloads.sourceforge.net/project/phpvirtualbox/phpvirtualbox-5.0-5.zip

Ensure zip/unzip are installed:
sudo apt install -y zip unzip

Unzip phpVirtualBox and rename the phpvirtualbox-5.0-5 to phpvirtualbox for ease of use:
sudo unzip phpvirtualbox-5.0-5.zip

Create a link to our served directory so we preserve original packaging for easier upgrades
sudo ln -s phpvirtualbox-5.0-5 phpvirtualbox

Next go to the /var/www/phpvirtualbox/ directory…
cd /var/www/html/phpvirtualbox/

… and create the file config.php by copying it from config.php-example:
sudo cp config.php-example config.php

Open config.php and fill in the password you created earlier for the vbox system user:
sudo vi config.php

[...]
/* Username / Password for system user that runs VirtualBox */
var $username = 'vbox';
var $password = 'pass';
[...]

Clean up Apache2 file privileges:
sudo chown www-data:www-data -R .

4. Clean up and reboot
As good practice I always update and clean up before rebooting when installing new software
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
sudo apt autoclean -y

sudo reboot now

5. Check the system
That’s it already – you can now open a browser and access phpVirtualBox as follows:
eg: http://www.example.com/phpvirtualbox/
or By IP:
eg: http://192.168.1.1/phpvirtualbox/

Default logon is admin:admin

One thought on “VirtualBox admin using phpvirtualbox

Leave a Reply