Skip to content

Sun VirtualBox as a virtual development environment for PHP

Dear Reader,

The problem

For the past year I’ve been looking at the way I develop web based projects and how I can make it easier, better, faster, more stable, but most of all, portable. Like many PHP developers out there, I work on multiple projects at the same time. It’s not unusual for me to have three projects under development at any given time with an additional five projects that I’ve abandoned that I’m not yet willing to delete. I’ve developed a way of working with them that works for me. I’ve even written a Zend Framework based cli tool that sets up my work environment the way I like it.

All of that is wonderful if I’m sitting here in my lair connected to my local network. However, if I’m moving around, I have two choices, setup something like Zend Core or XAMPP on my laptop and duplicate my development server. This is the model I’ve used for the past few years but what I end up with is projects on my development server that I wanted on my laptop and visa-versa. The more I thought about it though, the more I realized there had to be a better way. My current setup doesn’t allow me to do things like test PHP 5.3 without setting up a whole new server just for that purpose, or maintain an environment like my production server – it has it’s own little quirks – so that I can work on legacy code.

Here is a short list of my criteria:

  • Must work on my laptop.
  • Must allow me to easily test different environments
  • Must let me work on multiple projects

The solution that doesn’t work

Yesterday I was browsing like all good PHP developers should when I ran across a link to Kevin van Zonneveld’s blog post, How virtualization will improve your code. Reading it over, I begin to think he had hit upon the solution. He was using Sun’s new VirtulBox 2.0 to virtualize the development server. The only problem with Kevin’s solution is that he is running Linux as his primary OS (Host) and runs Linux as the virtualized (Guest) OS. Actually, it’s not a problem for him but it is for me since I use Windows as my desktop environment. I did feel though that he was moving in the right direction.

Installing VirtualBox is very easy and grabbing a copy of Ubuntu Desktop (Don’t use Server, it won’t work According to this thread The problem was a setting in VirtualBox and not Ubuntu itself. It may be safe to use Server if you like.) was actually the longest part of the process. Once downloaded, setting up the virtual server was actually anti-climatic. You just let the wizard get you going and then watch as Ubuntu installs.

One of the great things about VirtualBox is that it has a “shared folders” option. I simply define a directory on my Windows OS (Host), c:\web, as a shared folder and then mount that share inside the Linux OS. Once you you get it working the way you want, you jsut add the mount to your virtual server’s /etc/fstab and never think of it again.

The end result is I can still use Windows/Komodo as my development environment. My virtual server has Apache, PHP and MySQL installed so it can serve up the pages from the same directory. So far, all was going well. Here is where Kevin and I parted company though. Kevin was content to browse the work area using the browsers installed on the virtualized server. This is the easy way to do it because the browser and Apache are on the same virtual machine. I however, wanted to be able to browse the server from my Windows environment so I can test with IE, FF, Safari, etc.

Following the instructions in the Users Guide I setup a “Host Interface”, bridged it to my wi-fi card and setup my virtual server to use the new interface. (It should be noted that I know enough networking to be dangerous so the sentence above actually covered about 3 hours of running down blind alleys) Each time I tried a different combination, my new virtual server fired up just fine but failed to connect to the network.

After a lot of failed tries and a lot of googeling, I found the answer. (Which was, of course, in the manual to begin with) Most wi-fi cards are not capable of promiscuous mode. For bridging to work, Windows has to put the card in promiscuous mode.

Mine card, an Intel® PRO/Wireless 3945ABG, is capable of it but you have to have an admin tool to do it and while I can find the manual for the admin tool, I can’t find anyplace to download the actual tool itself.

Just to confirm that this was actually the problem, I snaked a cable into my lair from my server closet and bridged the host interface and my wired interface. Voila! it worked exactly how I wanted it to. But alas, since the solution is not portable, it won’t fit all my criteria.


Even though VirtualBox won’t meet my need as a development server, it’s still a cool toy to play with. It scratches my Linux itch while letting me keep my Windows desktop. Running it in seamless mode is a little more processor intensive but very cool. It puts the Linux toolbar at the top of the screen and Linux apps open as regular Windows windows.

I’m still in search of the perfect development environment. If I find it, I’ll let you know.

Until next time,