This was a major battle for me, but I finally got it all together. I think VirtualBox has a smaller footprint than VMWare (and doesn't install as many "services" in Windows) and in my testing, the virtual applicances are amazingly flexible and portable. Seems to work great, I thought, so I decided to uninstall VMWare and try to create an image from zero (basically).
- Install VirtualBox from Sun.
- Download Ubuntu 8.04 JEOS
- Make a new virtual machine which we'll call Ubuntu804Jeos. This name is important and we'll need it later.
- Follow your nose for creating a working Linux on VirtualBox. Basically, you mount the CD image and you're good to go. The Linux virtual machine is called the "guest" OS, whereas the system that runs VirtualBox is called the "host."
- From the guest, try to ping google.com. This must work. If it doesn't, either give up, go find help, or figure out what the problem is using Google and your big analytic skills.
- Now, on to the fun stuff....
You'll definitely want to stop using the VirtualBox interface and eventually you'll need to connect to the machine, so you'll need to set up SSH.
- On your host machine, install some kind of SSH client like Putty on Windows
- Install SSH on your server. Easy, right? Use
sudo apt-get install openssh-server
- How will you connect to the machine? Here's the fun part. After hours of not bothering to really understand the VirtualBox docs, I finally figured out that you don't have to change anything. From a Windows command prompt, find this program and run it with these parameters
VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP
VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22
VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222
- Don't close that window! Also, note that the name, UbuntuJeos804 was used from above. Substitute where necessary.
- Now you've configured your host machine's port 2222 to route to your guest machine's port 22.
- Now you can connect with Putty or whatever other ssh client to localhost port 2222 and you're connected.
That was so fun! So now you'll do the same with Apache (and we'll install the whole LAMP stack while we're here)
- From the guest (using SSH!), install the whole LAMP stack
sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server phpmyadmin
- Install lynx to have something to test with
sudo apt-get install lynx
- Try to connect to Apache from inside the guest
- You should see the default Apache page ("It works!").
- Now get connected from the host. We map from port 8087 on the host to the guest
VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestapache/GuestPort" 80
VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestapache/HostPort" 8079
- That should be it! Now point a browser on your host machine to localhost:8087 and you should see the same message.
- While we're here, let's try PHPAdmin out too. It should be at http://localhost:8079/phpmyadmin/.
Now you're done! No, just kidding. The guest is on your own machine! You must be able to share files directly.
- Using the VirtualBox GUI, add the Guest Additions. This will do nothing (but will halfway mount the CD for the guest additions).
- Mount the CD
sudo mount /media/cdrom
- Cd to the cdrom directory and try to run the Guest Additions
sudo sh VBoxLinuxAdditions-x86.run
- This will result in all kinds of errors, so run the following meaningless commands (in which we mess with the Kernel and do all other stuff that is somehow relevant)
sudo apt-get install gcc
sudo apt-get install make
sudo apt-get install build-essential
sudo apt-get install linux-headers-`uname -r`
- Reboot the machine.
- Do steps #2 and #3 again. Now you should have the Guest Additions installed.
That was necessary to be able to share a folder to your guest machine (adds the vboxsf file system type).
- Add a shared folder using the VirtualBox GUI. Mine is called ubuntu-share.
- Now we can mount that using this command
sudo mount -t vboxsf ubuntu-share /mnt/ubuntu-share
- Now your folder should be in /mnt/ubuntu-share
Now you might want to run the server "headless" once you don't need the GUI anymore. Use something like this
Conclusion, What's Missingstart "VirtualBox Headless" /b "C:\Program Files\Sun\xVM VirtualBox\vboxheadless" -s UbuntuJeos804
That's all I've got so far. The only thing that's missing, for my needs, is to make the mounting "sticky." I'll update this post when I figure that out.
Problems, comments, and corrections are all greatly appreciated.
Edit: I just wrote a bit more on this. Check out Virtual Hosts on Apache on your VirtualBox appliance.