How to install phpVirtualBox on Debian Jessie

Here are my notes on installing phpVirtualBox, a webbased graphical interface for VirtualBox, now recommended from VirtualBox’s site! These notes are for Debian 8.2 using Apache.

The web interface looks very similar to the original VirtualBox GUI and works very well.

phpVirtualBox01

If you haven’t done so already install Apache and php5:

# aptitude install apache2 php5

Installing VirtualBox
Source: https://www.virtualbox.org/wiki/Linux_Downloads

Add the following line to your /etc/apt/sources.list:

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

(If you’re using an other version of Debian change jessie to your version.)

Add Oracle VirtualBox’s keyfile to your system so the source is trusted. (Don’t do it if you don’t want automatic updates for VirtualBox.)

# wget https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | apt-key add -
# aptitude update
# aptitude install virtualbox-5.1 

Install the Extension Pack (check here which version is the current one first):

# wget http://download.virtualbox.org/virtualbox/5.0.10/Oracle_VM_VirtualBox_Extension_Pack-5.0.10-104061.vbox-extpack
# VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.0.10-104061.vbox-extpack

Set up your system
Create a dedicated VirtualBox user and create a password:

# useradd -d /home/vbox -m -g vboxusers -s /bin/bash vbox
# passwd vbox

You’ll need the password later on.

Tell your system which user is going to run VirtualBox. In /etc/default/virtualbox (create it if it doesn’t exist):

VBOXWEB_USER=vbox
VBOXWEB_HOST=127.0.0.1

VirtualBox has a web interface for just this kind of software. We’ll be running it as our vbox user because it doesn’t need access to the rest of your system.

# sudo -u vbox vboxwebsrv &

The ampersand at the end detaches the program from the console so if it’s running and you press Ctrl+C it won’t stop but you will be able to do other stuff in that console including closing it.

If VirtualBox is running on another server you must pass along its IP address here:

# sudo -u vbox vboxwebsrv -H 192.168.1.4 &

Have vboxweb-service start on boot so we don’t need to enter the command manually every time:
in /etc/init.d/vboxweb (create it):

#!/bin/bash
sudo -u vbox vboxwebsrv &

Make the script executable:

# chmod +x vboxweb

Tell Debian to run it at normal bootups:

update-rc.d vboxweb defaults

The remarks about the script being incomplete is expected. Feel free to improve it.

Reboot to see if it works.

Installing phpVirtualBox
Download phpVirtualBox and extract it as a subfolder of /var/www/html. For production machines place phpVirtualBox in its own directory and restrict access.

# aptitude install unzip
# cd /var/www/html
# wget http://sourceforge.net/projects/phpvirtualbox/files/latest/download -O phpvirtualbox.zip

Unzip the downloaded file:

# unzip phpvirtualbox.zip

Rename for easier access:

# mv phpvirtualbox-5.0-3/ phpvirtualbox

Copy the config file and edit it:

# cd /var/www/html/phpvirtualbox/
# cp config.php-example config.php

In /var/www/html/phpvirtualbox/config.php change:

var $username = 'vbox';
var $password = 'P@55w0rd';

Use the password you gave the vbox user earlier on.

Open your browser and point it to your server’s address followed by /phpvirtualbox, for example http://myserver/phpvirtualbox. Default username and password are both admin.

To view the VM, select it and on the right side click the Console button. If all is well you will be able to select your desired screen resolution and connect to the VM.

phpVirtualBox08

Pretty cool!

The part that provides this is actually an RDP client embedded in the VirtualBox Extention Pack. If it doesn’t work make sure you have the latest Extension Pack installed.

It is also possible (and faster) to view the VM from a locally installed RDP client.

If you’re on a Windows system just run

C:\>mstsc

or type remote desktop in the Start Menu box.

phpVirtualBox05

In the Remote Desktop Connection window type the IP address of the server hosting VirtualBox (not the address of your virtual machine) followed by the port number.

phpVirtualBox04

The port number defaults to 9000 but you can set it from the virtual machine’s properties in VirtualBox: Display > Remote Display.

phpVirtualBox06

A port or port range is accepted.

If unsure just check what the built-in console wants to connect to:

phpVirtualBox07

Remote Desktop will then show your virtual machine.

phpVirtualBox03

Alternatively select the VM in phpVirtualBox and from the Details window, under Display, click on the port number. This will fire up your RDP client.

There are terminal services clients for just about any operating system.

Notes:
– phpVirtualBox’s default username and password are both admin.

– VirtualBox’s default interface and phpVirtualBox even more so do not show all options. If you need to perform an operation on a VM that requires options not shown in the GUIs use the command line interface: VBoxManage. Its documentation is excellent and it allows you to access all available options.

– If you use VBoxManage remember to do it under the account of your dedicated VM user (c.q. vbox). If you use root or any other account not in /var/www/phpvirtualbox/config.php the operations will not be reflected in the web interface.

– phpVirtualBox major and minor versions always reflect VirtualBox versions.

– A very cool feature is remote usb. You can pass your usb device through to the VM via the remote display. Haven’t tested it yet but I will. Read all about it here!

– If you’re planning on running PfSense like I did or just *BSD check out this post on fixing a high CPU load.

If you’re looking for a VirtualBox backup script, you’re in luck!

Enjoy!

16 Comments

  1. Hello,
    Having no notion of English I use Google translation to dialogue with you (excuse)
    I followed your tutorial but I encounter the following problems:

    1)
    Update-rc.d vboxweb defaults
    Insserv: warning: ‘K01vboxweb’ missing LSB tags and overrides
    Insserv: warning: ‘vboxweb’ script missing LSB tags and overrides
    ————————————————– ————————————————– —
    2)
    -u lucie vboxwebsrv &
    [1] 7404
    Root @ proliant: ~ # -bash: -u: command not found
    ————————————————– ————————————————– —–
    I follow your tutorial but I arrive at the end with this error
    An unknown PHP error occurred. This is most likely a syntax error in config.php in phpVirtualBox’s folder. The most common errors are an unclosed quote or a missing semicolon in a configuration item that has been entered (e.g. location, username, or password).

    Depending on your PHP configuration, navigating directly to config.php in your web browser may display the PHP error message.

    I can have S.V.P a little help?

    Cordially lucien

    • Kapitein Vorkbaard

      Bonjour Lucien,
      C’était très bien traduit, mes compliments ;)

      1) C’est normal; c’est à cause de code manquant pas pertinent: https://wiki.debian.org/LSBInitScripts/DependencyBasedBoot.
      2) Ça manque: “sudo -H”. Veuillez faire: sudo -H -u lucie vboxwebsrv &

      I had the same error with this script today. I killed all VirtualBox processes (ps aux | grep -i [v]b and see which VirtualBox processes there are), then restarted vboxweb (service vboxwebsrv start), then it worked. I’m not sure what caused it.

      Bonne chance!

      • lucien

        Good evening
        Thank you very much for answering me :) I start on linux and it is not obvious
        In addition I do not find much help …. I make an attempt and
        I’ll let you know if you want to.
        It’s been a week since I blocked the phpvirtualbox and you’re the only one to answer.
        Ps: I’m on a ProLiant ML350 G6 server and a Debian Jessie.
        Lucien

        • Kapitein Vorkbaard

          You are most welcome. I suggest you start with Ubuntu for educational purposes. Ubuntu has a thriving community and many questions have already been answered: http://askubuntu.com/ It is easier to learn with Ubuntu than Debian. After a while you may want to go back to Debian as it is ‘purer’, but that is a matter of taste.

          Anyway, Ubuntu is easier for learning, in my opinion.

          • lucien

            Have already advised Ubuntu 16.0 TLS, but too much thing already installed on my Debian such as >> rtorrent / rutorrent + vpn :) plex, a mail server (postfix-raindloop)
            Ect .. a lot of work already for me :).
            It still works
              Root @ proliant: ~ # -bash: -H: command not found
            [1] + Termine 127 -H -u lucie vboxwebsrv
            Root @ proliant: ~ #
            Something missing in my system can be?

          • lucien

            It does not work
            Root @ proliant: ~ # sudo -H -u lucie vboxwebsrv &
            [1] 8762
            Root @ proliant: ~ # -bash: sudo: command not found
            ^ C
            [1] + Termine 127 sudo -H -u lucie vboxwebsrv
            Root @ proliant: ~ #

            Something going wrong on my system?

  2. lucien

    On the google browser >> “http: // proliant: 8080 / phpvirtualbox”

    I arrive on this error message
    An unknown PHP error occurred. This is most likely a syntax error in
    config.php in phpVirtualBox’s folder. The most common errors are an unclosed
    quote or a missing
    semicolon in a configuration item that has been entered (e.g.
    location, username, or password).
    Depending on your PHP configuration,
    navigating directly to config.php in your web
    browser may display the PHP error message.

    Sorry to spend your time.

    • Kapitein Vorkbaard

      No problem, Lucien. Please see my first answer ;) If you really can’t get it work I suggest you post your question on StackExchange.

      • lucien

        I have this message after the command “service vboxwebsrv start”
        root@proliant:~# service vboxwebsrv start
        Failed to start vboxwebsrv.service: Unit vboxwebsrv.service
        failed to load: No such file or directory.
        root@proliant:~#

        I will see to post a question about StackExchange

        Again thanks for the time spent
        good Sunday !

        • Hello,
          I managed to make it work :) … but not without bad
          I had to install Apache2 the way below>
          1) # apt-get -y install apache2 php7.0-php7.0 php-php7.0 libapr1 libapru1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libapr1 Php-soap
          2) in the file # / etc / php / 7.0 / apache2 / php.ini
          Change >> “;Extension = php_soap.dll” (I removed “;”the front)
          3) Then a script in # / etc / init.d / vboxweb with in >> “vboxwebsrv -H 127.0.0.1”
          Now phpvirtualbox rolls :)

  3. Important! To start the script this way
    #! / Bin / bash
     
    ### BEGIN INIT INFO
    # Provides: vboxweb
    # Required-Start: $ remote_fs $ syslog
    # Required-Stop: $ remote_fs $ syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0
    # Short-Description: Starts vboxweb service
    # Description: start vboxweb service at startup so
                          Not to enter the command manually each time
    ### END INIT INFO

    Can you already know? :)

  4. Alessandro Gonçalves

    Hello,

    I really wanna thank you for share this how to, i’ve done all without problems, successfully implementation.

    Best regards.

    Alessandro.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.