Creating a Headless VirtualBox VM Host on Ubuntu Server 🌱

Installation and Configuration

  1. Log into the Ubuntu Server host
  2. Run the following commands
    # update software repositories
    sudo apt update
    # install available software updates
    sudo apt upgrade -y
    # install virtualbox
    sudo apt install virtualbox -y
    # verify virtualbox installed by outputting the version
    vboxmanage -version
    # install virtualbox extension pack
    sudo apt install virtualbox-ext-pack -y
    # disable default vboxweb service
    sudo systemctl disable vboxweb
    # create vboxadmin user and set a password
    sudo useradd vboxadmin
    # set the vboxadmin password
    sudo passwd vboxadmin
    # add vboxadmin to the vboxuser group
    sudo usermod -aG vboxusers vboxadmin
    # create vboxadmin home directory
    sudo mkdir /home/vboxadmin -p
    # make vboxadmin the owner of the home directory
    sudo chown -R vboxadmin /home/vboxadmin
    # edit the default virtualbox configuration
    sudo nano /etc/default/virtualbox
  3. Add the following line to the bottom of the file, changing the username if necessary

    VBOXWEB_USER=vboxadmin
    VBOXWEB_HOST=127.0.0.1

  4. Press CTRL+O, Enter, CTRL+X to write the changes
  5. Continue with the following commands, changing the username if necessary
    # create vboxweb.sh
    sudo nano /home/vboxadmin/vboxweb.sh
  6. Paste the following into vboxweb.sh

    #!/bin/bash
    /usr/bin/vboxwebsrv -H 127.0.0.1 > /dev/null 2>&1

  7. Press CTRL+O, Enter, CTRL+X to write the changes
  8. Continue with the following commands, changing the username if necessary
    # make vboxweb.sh executable
    sudo chmod +x /home/vboxadmin/vboxweb.sh
    # create phpvirtualbox.service
    sudo nano /etc/systemd/system/phpvirtualbox.service
  9. Paste the following service configuration, changing the username if necessary

    [Unit]
    Description=VirtualBox Web Service
    After=network.target

    [Service]
    Type=simple
    RemainAfterExit=yes
    User=vboxadmin
    Group=vboxusers
    WorkingDirectory=/home/vboxadmin
    ExecStart=/home/vboxadmin/vboxweb.sh
    Restart=on-failure

    [Install]
    WantedBy=default.target

  10. Continue with the following commands
    # enable phpvirtualbox.service
    sudo systemctl enable phpvirtualbox.service
    # start phpvirtualbox.service
    sudo systemctl start phpvirtualbox.service
    # install apache2 web server and php
    sudo apt install apache2 php libapache2-mod-php php-curl php-intl php-json php-gd php-mbstring php-xml php-zip php-soap -y
    # empty the apache2 web root
    sudo rm /var/www/html/*
    # install git
    sudo apt install git -y
    # clone phpVirtualBox git repository
    sudo git clone https://github.com/phpvirtualbox/phpvirtualbox.git /var/www/html
    # copy phpVirtualBox example config
    sudo cp /var/www/html/config.php-example /var/www/html/config.php
    # edit the config file
    sudo nano /var/www/html/config.php
  11. Update the $username and $password variables to vboxadmin and the password set for the vboxadmin user
  12. Press CTRL+O, Enter, CTRL+X to write the changes to config.php
  13. Open a web browser from another machine and navigate to https://DNSorIP of the VirtualBox host
  14. Log into phpVirtualBox with username admin and password admin

Creating a Test VM

  1. Run the following command on the VirtualBox host to download the TinyCore Linux .iso
    sudo wget -O /home/vboxadmin/TinyCore-12.0.iso http://tinycorelinux.net/12.x/x86/release/TinyCore-12.0.iso
  2. In the phpVirtualBox web UI, click New
  3. Set the Name to TinyCore Linux, Type to Linux and Version to Other Linux (32-bit) > Click Next
  4. Leave the memory at 256 MB > Click Next
  5. Select Do not add a virtual hard disk > Click Create
  6. Click Continue to confirm creating the VM with no virtual hard disk
  7. Right click the TinyCore Linux VM > Settings...
  8. Select Storage from the left navigation menu
  9. Click on the empty optical drive
  10. Click the choose disk image dropdown > Choose a virtual disk file...
  11. Navigate to /home/vboxadmin/TinyCore-12.0.iso and select it
  12. Click OK to all open dialog windows
  13. Right click the TinyCore Linux VM > Start
  14. If everything is working as expected TinyCore Linux should be booting to the live environment
  15. Look at the Display details to find the remote port (starts at 9000 by default)
  16. To view the VM directly, remote desktop to the VirtualBox host IP:9000