Setting up a headless VirtualBox webserver on Windows Server 2003 R2

virtualbox_logo

VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only is VirtualBox  an extremely feature rich, high performance product for enterprise customers, it is also the only professional solution that is freely available as Open Source Software under the terms of the GNU General Public License (GPL). See "About VirtualBox" for an introduction.

Presently, VirtualBox runs on Windows, Linux, Macintosh and OpenSolaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista, Windows 7), DOS/Windows 3.x, Linux (2.4 and 2.6), Solaris and OpenSolaris, and OpenBSD.

VirtualBox is being actively developed with frequent releases and has an ever growing list of features, supported guest operating systems and platforms it runs on. VirtualBox is a community effort backed by a dedicated company: everyone is encouraged to contribute while Sun ensures the product always meets professional quality criteria.

This tutorial will guide you how to set up a headless VirtualBox webserver to connect to your virtual machines from another host. This gives you multiple advantages including administering virtual machines without performance loss on your own system. You don't even need to run the VirtualBox GUI on you own system, let alone having VirtualBox installed on your own system. The only thing you need to administer you headless virtual machines is an RDP connection, so it's amazingly performace friendly on you own system as it doesn't use your system's resources. The virtualbox webserver can even be configured to run and administer virtualbox system within your browser.

It's like having all the pros of the virtualization concept without the cons!

Moving on to the installation part. This tutorial will guide how to set up a VirtualBox webserver on Windows Server 2003 R2 and will most likely work fine as well on the standard Windows Server 2003. This tutorial also assumes you fully updated your Windows Server 2003 R2. The XAMPP installation will be covered in the tutorial, but if you already set up XAMPP you can safely skip that part of the tutorial.

Please note that by the time I wrote this article phpVirtualBox 0.5 and VirtualBox 3.2.8 were the most recent packages so you might want to change the download links and the package names to whatever matches the now most recent versions.

 

  1. Installing XAMPP
     First we'll need to install XAMPP in order to make it possible for us to use the Web UI (which I strongly recommend). I know what you're thinking: "Why not use IIS?". Well, to be honest I initially tried using IIS because I just wanted it to work without needing as much third-party software. And since IIS is Microsoft, I wanted it to work with IIS from the start. Sadly, this did not go well... and even the creator of phpVirtualBox advised against this "instead of mucking around with IIS, you may install XAMPP or XAMPPLite". I didn't really paid much attention to the above statement, but realised soon enough that I was going nowhere. IIS really drove me insane at some point and at the end I simply gave up on IIS.

    So there. That's why I wrote this tutorial with XAMPP instead of IIS. If you still want to use IIS instead of XAMPP, be my guest and knock yourself out. No kidding, really, I hope you do it because I really want to know how to get phpVirtualBox to work with IIS. It has to be possible, I know it, but I couldn't figure it out so if you can get it to work with IIS I really want to know how you managed that. I'm sure a lot of guys out there would like to know too so maybe post a reply to your blog or anything.

    Moving on, if you're using a virtual machine, make sure to have your network adapter bridged to your physical network adapter. In any case you want to make sure to assign the network adapter with a static TCP/IP configuration.

    You can start downloading XAMPP using this link: http://www.apachefriends.org/en/xampp.html

    vbox_win2003_screenshot_1

    I'd advise you to install XAMPP to the root of the hard disk. Don't worry, it'll extract all the files to a seperate xampp directory. Also, you might want XAMPP on a seperate partition. If you do, just change the drive letter given to your other partition.

    vbox_win2003_screenshot_2

    The installation will now extract its files. This shouldn't take too long.

    vbox_win2003_screenshot_3

    After extraction XAMPP will ask you to install shortcuts to your startmenu and your desktop. I suggest you to do this even if you don't like shortcuts on your desktop, because telling XAMPP not to do so will make XAMPP to skip the installation of shortcuts to your startmenu. And you most likely do want to manage XAMPP from your startmenu even if you don't want to manage it from your desktop. And you can simply delete the shortcuts on your desktop while leaving the shortcuts in your startmenu be.

    vbox_win2003_screenshot_4

    Soon after, XAMPP asks you to continue iinstalling XAMPP. Enter yes here, because that was the whole point...

    vbox_win2003_screenshot_5

    Unless you plan to move your XAMPP installation around using a USB flash drive, I'd advise to enter no here. If you do, then you had better make sure to install this XAMPP installation to your USB flash drive's root folder from the very beginning.

    vbox_win2003_screenshot_6

    Just press the Enter button here.

    vbox_win2003_screenshot_7

    Usally XAMPP detect the proper timezone and informs you about this. This window gives you the possibility to change it if needed.

    vbox_win2003_screenshot_8

    Enter 1 here to automatically start XAMPP.

    vbox_win2003_screenshot_9

    XAMPP should now have been started button right on your screen.

    vbox_win2003_screenshot_10

    The command prompt window stays open after you started XAMPP. You can safely exit this window by entering x here.

    vbox_win2003_screenshot_11

    Tick the checkbox on the left of Apache to make sure Apache will be started as a service from now on. After installing Apache as a service, start it by clicking the Start button on the right of Apache.


  2. Installing VirtualBox
    Now we can install VirtualBox. Go over to this website and download the latest VirtualBox from there: http://www.virtualbox.org/wiki/Downloads. Once the download is finished you'll be presented with a screen like this.

    vbox_win2003_screenshot_12

    Click next to start the installation.

    vbox_win2003_screenshot_13

    Accept the license agreement and continue.

    vbox_win2003_screenshot_14

    Make sure to instal all features. This also enable you to use the GUI from time to time, which can be pretty useful.

    vbox_win2003_screenshot_15

    Personally I'm not very fond of my sytem overfilling itself with every shortcut, but if you're ok with it, then you might want to tick the box that applies to your personal needs.

    vbox_win2003_screenshot_16

    This is simply just a warning that prcoeeding with this step, you'll lose your connection to the internet for a moment. This will only be temporary, but it's nice to know about this fact.

    vbox_win2003_screenshot_17

    Click on the install button whenever you're ready.

    vbox_win2003_screenshot_18

    The installation shouldn't take very long, bnut you might be presented with several windows like this one:

    vbox_win2003_screenshot_19

    This is a warning that the installer is installing a non-Windows verified software package or driver. This is totally normal and it's safe to click the continue anyway button here.

    vbox_win2003_screenshot_20

    Once the installation is finished, we don't need to start it. So untick the checkbox and click finish when you're done.


  3. Installing the VirtualBox webserver as a service
    In order to make the VirtualBox webserver to automatically start during start-up we need to make this a service. Now, to do that, we need to install the Windows Server 2003 resource kit tools to create a custom service. Download the rources kit here: http://www.microsoft.com/downloads/en/details.aspx?familyid=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

    vbox_win2003_screenshot_21

    Once you downloaded the resource kit, install the package.

    vbox_win2003_screenshot_22

    Accept the license agreement and click next.

    vbox_win2003_screenshot_23

    Just type in your name and maybe a dash to cover the organization text field and click next here. I don't mind and neither does VirtualBox.

    vbox_win2003_screenshot_24

    Choose where to install the resource kit. I'd advise you to leave this path as it is because it'll only take 37 MiB of your hard drive.

    vbox_win2003_screenshot_25

    The resource kit is installing itself now. This shouldn't take too long.

    vbox_win2003_screenshot_26

    Once the installation is complete you can safely click finish here.
    The next thing we want to do is making a blank service which we'll configure to automatically start the VirtualBox webserver.

    vbox_win2003_screenshot_27

    Open up command prompt window and enter the following line:

    "%PROGRAMFILES%\Windows Resource Kits\Tools\Instsrv.exe" "VirtualBox Webservice" "%PROGRAMFILES%\Windows Resource Kits\Tools\srvany.exe"


    vbox_win2003_screenshot_28

    The command prompt will notify you afterward once the blank service was installed succesfully. Now all we got to do is configure it.

    vbox_win2003_screenshot_29

    Fire up the register editor and browse to the following key:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VirtualBox Webservice


    vbox_win2003_screenshot_30

    Once there, create a new key by going to Edit -> New -> Key.

    vbox_win2003_screenshot_31

    Name your new key Parameters.

    vbox_win2003_screenshot_32

    Browse to your new key and once you're there, go to Edit -> New -> String Value to create a new string.

    vbox_win2003_screenshot_33

    Name your new string Application and double-click it to change its values to match this:

    C:\vboxwebsrv.bat


    vbox_win2003_screenshot_34

    Like this. We'll be creating our custom batch script after we close the registry editor.

    vbox_win2003_screenshot_35

    Now close the registry editor safely by going to File -> Exit. Of course we can't use the service yet because it's trying to invoke a file that doesn't exist yet. To solve this we'll need to creat it.

    Open up a text editor like notepad and fill it with the following script:

    @ECHO OFF
    "C:\Program Files\Oracle\VirtualBox\vboxwebsrv.exe" >nul
    EXIT


    Save the file to C:\vboxwebsrv.bat

    The service should now be correctly installed and can be manually started by issuing the following command in a command prompt window:

    NET START "VirtualBox Webservice"


    vbox_win2003_screenshot_36

    If the service successfully started you'll be presented with a similar output I received.


  4. Installing phpVirtualBox
    Now we'll be downloading a very nice package which will enable us to administer our virtual machines thourgh our web browser. Start by downloading phpVirtualBox here: http://code.google.com/p/phpvirtualbox/downloads/list

    vbox_win2003_screenshot_37

    Once you downloaded the archive, extract the contents to C:\xampp\htdocs (you might want to rename the phpvirtualbox-* folder to simply phpvirtualbox).

    Now open the phpvirtualbox\config.php file in your text editor and look-up teh following lines:

    var $username = 'ian';
    var $password = 'pass';
     


    Make sure to replace ian and pass to your administrator account and the administrator's password.


  5. Using our browser to administer VirtualBox
    Great, now you can see if you can access VirtualBox at another (or the same) system with our web browser. Try connecting to it by using your IP-address, followed by a forward slash and phpvirtualbox. Your URL should look like something like this: http://192.168.1.5/phpvirtualbox.

    vbox_screenshot_1


  6. Finding your way around
    As you can see, the Web UI looks very similar to the normal GUI that you're used to. On of the first things you'll notice is that you can actually connect to all your virtual machines from within your browser. This is really convenient, but you can even connect to your virtual machine via Remote Desktop. This doesn't mean that you're stuck to use Windows machines in order to connect to because you're connecting to your virtual machine via Remote Desktop. No, the reason for that is that the guys behind VirtualBox were savvy enough to make sure Remote Desktop would connect to your virtual machine by using their own RDP connection: VRDP.

    VRDP is a compatible implementation of Microsoft’s Remote Desktop Protocol (RDP) that is configured for easy console access to the guest platform from remote systems. This means that you don't need to enable Remote Desktop on your Windows virtual machine, because it's not using that. It really connects directly to you virtual machine as if you would open the virtual machine normally in your GUI. While you're connected using VRDP you can even follow the boot procedure, which means you don't need to wait until Windows has started (because it's not using your usual RDP in Windows). And that means you can install whatever operating system you want (so not just Windows in order to use VRDP) on a virtual machine and still be able to take control over it by using Remote Desktop on a remote computer. The only thing you need to configure is to enable the virtual machine to use VRDP which can be configured when you open the settings of a virtual machine. You can configure VRDP here:

    vbox_screenshot_2

    Note that you don't have to limit yourself by using port 3389 as you normally would with a native Windows RDP connection. You could enter any port you like here, but be sure not to use a port below 1024. Once you chose an available port, you can even open this port in your router at home and you can connect from to your virtual machine from over the internet. And if you open port 80 in your router, you can also connect to your Web UI from over the internet, but I'd advise against that as it wouldn't ask for login credentials, so if anyone would happen to know your IP-address he or she could easily compromise your system. Fortunatly they're countless ways to prevent this. For example by making sure your phpvirtualbox folder would be protected with  with .htaccess file and a seperate .htpassword file.

    vbox_screenshot_3

    In order to connect to your virtual machine, you could either manually try to connect to them, or you could easily click the port number in the settings overview and a custom .rdp file will be created for you.

    vbox_screenshot_4

    You can open this file and you'll automatcally connect to your virtual machine, just like that.

    At first you'll notice the mouse from the virtual machine doesn't really seem to stick to your actual mouse pointer on your own machine. Don't let this dissapoint you as this problem can be easiily solved by making sure you installed the VirtualBox Guest Additions.

    Now, I can imagine you probably don't know where to find the VirtualBox Guest Additions image, but it's most likely located in the default folder (C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso).

    vbox_screenshot_38

    Mount the image in your virtual machine and install the VirtualBox Guest Additions to make the mouse pointer behave normally.


  7. Done!
    Congratulations, you successfully set up a VirtualBox webserver you can connect to to administer your virtual machines from.