Posts Tagged ‘linux’

My Development Environment

Sunday, November 1st, 2009

The Old

Most developers I’ve encountered run a local LAMP stack (WAMP5, MAMP, etc), but I think they suck:  they abstract away the cool stuff, like compiling extensions, modules and other fun software that you might want to play with. How’s a newbie going to learn some Apache administration if all they do is press a button called “Start Apache”? Some, myself included, run a separate Linux server. The benefits of having your own linux box for development include having an environment closer to production (assuming you deploy on linux), more flexibility in the software that you compile on it, and somewhere to practice your linux-fu. It’s just better.

I use an online box for development (an Amazon EC2 instance specifically) which means it’s accessible anywhere I am, so long as I have a decent internet connection. Others have a machine on their local network, which removes the internet requirement, but introduces a physical constraint. Some crazy fools run linux as a desktop, which is probably not acceptable for most people. Recently the network connection at my office has been crappy and is beyond my control. This has interupted my coding  so I’ve taken the opportunity to freshen things up and switch to using a virtual machine, as well as finally dropping ZDE 5.5.

The New

My new environment is similar to the old: I still use my Mac for writing code and I still run a linux server; the difference is by running the linux server as a virtual machine (via VMWare) I eliminate the network connection. This is the best of both worlds: I write code locally (on my pretty Mac) but also have a linux environment.

VMWare Fusion can be configured to provde your instances with static IPs, which lets you make an entry in /etc/hosts for a domain like devserver.

There isn’t anything special about this setup but I’m very happy with the glue/configuration that holds everything together.

MacFuse: exposing the VM’s filesystem

MacFuse is a cracking piece of kit. It allows you to “mount” a remote filesystem using SSH (or whatever protocol you like). This means my Mac has a path /Volumes/devserver that points to the /home/richard path on devserver. My IDE can now open and edit files on my linux server as if they were local.

I also run a SSH server on devserver and shell into it from my Mac Terminal. The VMWare window is permanently minimized and I rarely interact with the GUI.

Netbeans 6.7 - win!

Finally. I can say farewall to my old friend Zend Studio 5.5 :D. It’s a bit of a shame Zend went down the Eclipse route imho, I liked the old ZDE, but it’s time to move on. I’m not sure entirely what changed since Netbeans 6.5, but whatever it is I like. It took a few hours of fighiting but I beat it into submission  (I really dislike their “Run Configuration” dialog when creating a new project). In Netbeans-speak, my projects are setup as “local server”, but with a “remote” hostname (devserver). The sources directory is set to something like /Volumes/devserver/projects/myproject.

The feature that made it possible for me to switch is the new “Path Mapping” capability for debugging (Project Properties -> Run Configuration -> Advanced…). It maps a remote path (/home/richard/projects/myproject/www/foo.php) into a local path, so that the IDE can open up a local file to display the debugging stuff (ie /Volumes/devserver/projects/myproject/www/foo.php). In my setup, the translated local path is actually the remote file, due to the MacFuse magic. This means Netbeans will display exactly the same file as the debugger on the remote server is working with. Neat trick! (I also had to create a mapping to my devserver’s PHP include_path, which was /usr/local/lib/php => /Volumes/devserver/.phplib, where the .phplib was a symlink to /usr/local/lib/php). (This allows me to debug any PHP libraries that I have installed.)

Apache Magic: mod_vhost_alias

The module mod_vhost_alias allows you to dynamically create new virtualhosts without editing any config files. I have it setup so that a domain in the format XXX.devserver points to the document root /home/richard/projects/XXX/www. So when I create a new project in my editor at /Volumes/devserver/projects/new-project it is immediately available to view, debug or profile at http://new-project.devserver.

Conclusion

I’m happy. This feels like a nice, self-contained environment.

  • Develop on a linux server.
  • Write code on my Mac (or Windows).
  • Not reliant on the network.
  • Can do “remote” debugging.
  • Netbeans is lightweight and pretty.
  • Bonus: Kcachegrind is available to me through the VMWare instance.