Installing a virtual machine as a server with VirtualBox
After 4 long months without internet connection at home, here we are again! This time I decided to install the VirtualBox to explore it a little deeper, I've had some experiences with it some time ago but the only thing I can recall is that it ran Age of Empires 2 better than VMWare.
For those that don't know, VirtualBox is a virtualization framework developed by innotek and bought by Sun, yes... that Sun, the owner of MySQL, Java, OpenOffice and a couple of other famous softwares.
The goal of this endeavor was install a virtual machine (vm) to use as a web server to test small projects and learn. First, I installed a vm with Debian Etch and no graphical interface over VirtualBox in a openSuse 11.0. Then I installed Apache, MySQL, SSH and others... Now we get to the interesting part, how to make the hosting system have access to the servers and applications installed on the guest system.
With the vm's network interface configured with NAT (default option I guess), you just need to add the NAT port forwarding rules between the host and guest systems. As an example I'll use Apache, you'll need the three following command lines (the vm must be turned off):
$ VBoxManage setextradata "Debian" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/Protocol" TCP
$ VBoxManage setextradata "Debian" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/GuestPort" 80
$ VBoxManage setextradata "Debian" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/HostPort" 8080
With that done, just turn on your virtual machine again and test! If everything is configured correctly, the address http://localhost:8080 should take you to the pages stored on the guest system's Apache server.
On the command lines above, the name "Debian" refers to the name of the virtual machine you set on VirtualBox when creating it, the "apache" can be replaced with anything, it's just a name for the configuration. Also the ports used could be changed as you prefer, the ones displayed were the ones I used here, but it's pretty much up to you. The VirtualBox manual tell us that under linux hosts we must not use ports under 1024 for the "HostPort" because they are reserved for applications ran by root and the vm may not start in this case.
The only problem I'm having so far is the fact that I can't connect to the MySQL server installed on the guest machine and get the following error message:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
If anyone knows something about it, please leave a comment!
See you.