Local Web Development

I’m not ashamed of it: I like Windows. I think the user experience is light-years ahead of Gnome and KDE. There’s nothing ostensibly wrong with OS X, but there are little usability differences and frankly switching isn’t worth the annoyance to me. That’s why I run Windows 7 on all three computers I use daily.

This is only a problem when I try to work on LAMP web applications. Sure, I could install XAMPP, but running Apache/PHP on Windows is really not close enough to a production environment. So I have two choices: I can dual-boot Linux and work in an OS—well, a window manager—I don’t like, or I can turn to virtual machines.

VMWare is a pretty heavyweight solution. Fusion, for OS X, is a great product. But in Windows, I opt for Sun’s VirtualBox.

![VirtualBox New Virtual Machine Wizard](http://coffeeonthekeyboard.com/wp-content/uploads/2009/12/virtualbox-new-300x206.png "virtualbox-new")VirtualBox New Virtual Machine Wizard
VirtualBox lets me run Linux (I opt for [Fedora](http://fedoraproject.org/get-fedora) as it’s close to our production environment and I like it) in just another window, right next to Firefox.

To create a new VM, you’ll only need VirtualBox and a Linux ISO. (Or, you could use a pre-existing VM, or an “appliance,” copied from somewhere else. I’m not going to cover that.) Step through the wizard. Some of my recommended settings:

![VirtualBox New Disk Settings](http://coffeeonthekeyboard.com/wp-content/uploads/2009/12/virtualbox-disk-300x268.png "virtualbox-disk")VirtualBox New Disk Settings
- At least 512 MB of RAM for running Gnome+Apache+MySQL+VIm(+Firef0x?) in the VM. - At least 30 GB of hard disk. Yes, you can add more later, but expanding an existing disk is difficult, and if you use a “Dynamically expanding storage”-type of disk (see above) it won’t take the full 30 GB right off the bat. - There are two ways to go about doing Network settings—I do both. - Use Bridged networking. This gives your VM an IP address accessible to the rest of your network. - Use NAT. This gives your VM an IP address on a virtual network that only exists in your computer, but with a virtual gateway giving your VM access to the internet. - (You can also use Host-only networking, but that would prevent your VM from accessing the internet at all, and that’s no good.) - Mount your installation media ISO as a CD/DVD drive via VirtualBox. You’ll be able to boot off the ISO and install Linux. You may run into issues if you leave the ISO mounted after installation.
![VirtualBox Network Settings](http://coffeeonthekeyboard.com/wp-content/uploads/2009/12/virtualbox-network-300x260.png "virtualbox-network")VirtualBox Network Settings
Once you’re in Linux, set up your web server environment (use yum, apt-get, or whatever other package manager you choose). The key software I use:
  • Apache
  • PHP
  • MySQL
  • Memcached
  • Sphinx
  • Squid

With the software above, I can very nearly replicate the production environment for our web applications, while still spending most of my time in Windows. (When I do switch to the VM, I’m usually in VIm, my favorite text editor, anyway.)

Apache/PHP/MySQL is the typical PHP app stack. We use memcached for output caching (on SUMO, anyway). We use Sphinx to power our search engine. Squid is useful from time to time for approximating an application behind a reverse-proxy cache and load-balancing server. (You could also use nginx or Varnish.)

If you use NAT or Bridged networking, you’ll be able to navigate to your VM’s IP address from a browser on the host computer (in my case, in Windows). By using Bridged, I can access my local Apache instance from browsers on Windows, Linux, or a nearby Mac, which is immensely valuable when doing browser support work and testing. I can even send my VM’s IP address to other people in the office and have them look at my local work.

There is a performance cost with a VM. HTTP requests would come back faster in a real Linux environment, and sometimes I do boot into Linux, but the convenience is worth it to me.