How To Install VirtualBox On A Headless Ubuntu 14.04 Server And Manage It With phpVirtualBox

Yesterday we wrote about installing VirtualBox in CentOS 7 and managing it with phpVirtualBox tool on a headless CentOS 7 server. That tutorial was well received so we decided to write a similar one for Ubuntu 14.04.

If you want to reference the similar for CentOS 7, read click this link to go to the post.

This brief tutorial is going to show you how to install VirtualBox on a headless Ubuntu 14.04 server and manage it via a web browser using phpVirtualBox software.

When configured correctly, you won’t need to be physically connected to the Ubuntu server to manage virtual guests creation and deletion. You’ll be able to do it from a remote location via your web browser.

In order for this to work you’ll need Apache2, PHP and support modules along with phpVirtualBox packages. Carry out the setup on a Ubuntu box is much easier than on a CentOS 7 machine, that’s because of the firewall and SELinux applications that come pre-installed in CentOS.

When you’re ready, sign on to your Ubuntu machine and run the commands below to update it first. Before installing software in Ubuntu, it’s already a good thing to update.

Run the commands below to update Ubuntu.

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

After that, run the commands below to install required kernel-headers and kernel packages.

sudo apt-get install build-essential dkms

 

Next, run the commands below to create a separate VirtualBox repository file in Ubuntu.

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

 

Then copy and paste the below line in the file and save it.

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

 

Next, run the commands below to download the repository key and install.

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

 

Finally, run the commands below to install VirtualBox

sudo apt-get update && sudo apt-get install VirtualBox-4.3

 

Nex,t run the commands below to download VirtualBox extension pack. This pack allows VirtualBox to function smoothly and interact with the host computer properly.

cd /tmp/ &&  wget http://download.virtualbox.org/virtualbox/4.3.12/Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack

 

Next, run the commands below to install the extension pack.

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack

 

After installing VirtualBox, go and create a dedicated user to manage VirtualBox connections. To do that, run the commands below to create a username called richard, a password for richard account and add the user to VirtualBox users group.

sudo useradd richard
sudo passwd richard
sudo usermod -aG vboxusers richard

After that, run the commands below to test if VirtualBox was correctly installed and loaded. To do that, run the commands below.

sudo /etc/init.d/vboxdrv status

 

If it’s not correctly installed, run the commands below to re load the kernel modules

sudo /etc/init.d/vboxdrv setup

 

  • Installing Apache2, PHP and PHP Modules

After installing and configuring VirtualBox, let’s go and install Apache2 and PHP and its modules. To do that, run the commands below.

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

 

  • Installing phpVirtualBox in Ubuntu 14.04

Now that VirtualBox, Apache2 and PHP are installed, lets’ go and download phpVirtualBox package. To do that, run the commands below.

cd /tmp/ &&  wget http://sourceforge.net/projects/phpvirtualbox/files/phpvirtualbox-4.3-1.zip

 

Next, run the commands below to unzip the downloaded package

unzip phpvirtualbox*.zip

 

Next, create a root directory for phpVirtualBox.

sudo mv phpvirtualbox-4.3-1 /var/www/html/phpvirtualbox

 

Now copy the sample config file and rename it by running the commands below.

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

 

Then edit the configuration and add the user account and password you created earlier.

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

 

Add the info for the user
[...]
var $username = 'richard';
var $password = 'my_password';
[...]

Next, create a new VirtualBox file and enter the info for the user as shown below.

sudo vi /etc/default/virtualbox

 

Then enter the info for the user and save the file.

VBOXWEB_USER=richard

 

Start VirtualBox web service by running the commands below.

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

 

Open your favorite web browser and connect to the server. You’ll be prompted with a logon page.  The username and password are admin

username: admin

password: admin

 

phpvirtualbox setup on ubuntu

 

Logon and start creating guest operating systems.

 

phpvirtualbox on ubuntu

 

At the end, I ran into trouble using the new user info created above. I had to switch to my Ubuntu user account to get vboxweb-service started.

 

Enjoy!

Invest in some screen real estate with a new big screen, backlit monitor availabe in five different sizes and price points.

31 thoughts on “How To Install VirtualBox On A Headless Ubuntu 14.04 Server And Manage It With phpVirtualBox”

  1. Error in command line “sudo apt-get install apache2, php5 php5-common php-soap php5-gd”
    “apache2,” – The comma is not needed=)

    1. Yes please help. I also get the “fail!” when running the service start command. Where do we need to look for errors we have created?
      Thanks.

    2. Okay, it’s quite simple. For some reason the kernel modules got unloaded. That’s why I got the fail. Try running ‘sudo /etc/init.d/vboxdrv setup’ again (takes a while) and everything should work properly.

      1. nothing ….
        do “sudo /etc/init.d/vboxdrv setup” again , waiting to be done and result
        sudo /etc/init.d/vboxweb-service start —> Starting VirtualBox web service …fail!
        (Linux ubuntu 3.13.0-43-generic #72-Ubuntu x86_64 x86_64 x86_64 GNU/Linux)

        1. some how i manage to recover fail service.
          1. sudo /etc/init.d/vboxdrv stop
          2. sudo /etc/init.d/vboxdrv setup
          3. sudo /etc/init.d/vboxdrv start
          4. sudo /etc/init.d/vboxweb-service start -> Starting VirtualBox web service …done.

          now i get in web -> [message:protected] => Could not connect to host (http://127.0.0.1:18083/)
          go for i ride …

    3. I had a totally different cause of the “…fail!” error when trying to start vboxweb-service. In my case it was because the log file was not writable by the user (VBOXWEB_USER variable in /etc/default/virtualbox, in my case set to user “vbox”). On my Ubuntu 14.04 system I had to do the following:

      touch /var/log/vboxweb.log
      chown vbox.vboxusers /var/log/vboxweb.log
      usermod -G syslog -a vbox

      The reason for the “usermod” line is that the /var/log directory has rwx permission for group “syslog”, if you add your user to the “syslog” group it will be allowed to write to files in the /var/log directory, otherwise it won’t. You can verify the permissions on the directory with “ls -ld /var/log”.

  2. Thanks for the guide, howvever eventually I got
    sudo /etc/init.d/vboxweb-service start
    Starting VirtualBox web service …fail!

    The fix was (using your username in this case):

    $ sudo mkdir /home/richard/
    $ sudo mkdir /home/richard/.VirtualBox
    $ sudo chown richard:vboxusers /home/richard/.VirtualBox
    and it worked like a charm.

    1. same trouble, however I didn’t see the “fail!” error message. It seemed to start ok, but there was nothing listening on the web service port. An strace led me to the missing home directory. Glad to see you got it sorted.

  3. I am getting an error when logging into the vboxwebsrv. I’ve followed everythign in this article including the fix info from Dunq (which got me a lot further btw, thanks Dunq). I am including the details. any ideas? Thanks!!

    Exception Object
    (
    [message:protected] => Error logging in to vboxwebsrv.
    [string:Exception:private] =>
    [code:protected] => 64
    [file:protected] => /var/www/html/phpvirtualbox/lib/ajax.php
    [line:protected] => 128
    [trace:Exception:private] => Array
    (
    )

    [previous:Exception:private] =>
    )

  4. Hello,

    I followed this tutorial pretty much down to the letter (save a different user name). Everything works as one would expect. I am able to connect to the server using the IP address that has been assigned to the physical machine using DHCP (static IP address). I am able to log in, create virtual machines, etc. Problem… I only have the 32 bit machines available as options inside the web interface. I double checked to ensure that my hardware is indeed 64 bit and that I had installed a 64 bit version of the Ubuntu server operating system as the host OS. However, I still do not have 64 bit version OS options inside the virtual box interface. Has anyone else encountered this issue/know how to fix it. FYI, I am fairly new to Linux. However, I am definitely interested in tinkering around with things. I just may need a little more help that your average nerd. ;-)

    Thanks,
    Jason

  5. I can say that I followed this procedures to install virtualbox using Oracle_VM_VirtualBox_Extension_Pack-4.3.34-104062.vbox-extpack, and it worked fine with the exception that I also ran into the: Starting VirtualBox web service …fail!

    ———————–
    sudo /etc/init.d/vboxweb-service start
    Starting VirtualBox web service …fail!

    The fix was (using your username in this case):

    $ sudo mkdir /home/richard/
    $ sudo mkdir /home/richard/.VirtualBox
    $ sudo chown richard:vboxusers /home/richard/.VirtualBox
    ———————–

    and it worked like a charm as posted by Dunq.

  6. Well this was several hours I’ll never get back. phpvirtualbox-4.3-1 is no longer available so used 4.3-3. got the failed to start message so tried the above fix using the home folder thingy, still wouldn’t start, so tried the sudo vboxwebsrv thing. I now have a very nice door stop. server boots but is unresponsive. Now I have to re-install ubuntu server.

  7. For the love of God! my keyboard was unplugged! WTF!!?

    Had to re-run “sudo /etc/init.d/vboxdrv setup”

    All is working now, Thank you for the tutorial!

  8. As I login with admin creds, I get “Error logging in to vboxwebsrv.”

    Exception Object
    (
    [message:protected] => Error logging in to vboxwebsrv.
    [string:Exception:private] =>
    [code:protected] => 64
    [file:protected] => /var/www/html/phpvirtualbox/endpoints/api.php
    [line:protected] => 134
    [trace:Exception:private] => Array
    (
    )

    [previous:Exception:private] =>
    )

Leave a Reply

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