VMWare, Samba, Eclipse, and XDebug: Mixing a virtual Linux environment with a Microsoft Windows development environment

I’m starting the second phase of a Drupal development project, which means I get to write about all sorts of geeky things again. Hooray! So I’m investing some time into improving my environment set-up, and taking notes along the way.

This time, I’m going to try developing code in Eclipse instead of Emacs, although I’ll dip into Emacs occasionally if I need to do anything involving keyboard macros or custom automation. Setting up a good Eclipse environment will help me use XDebug for line-by-line debugging. var_dump> can only take me so far, and I still haven’t figured out how to properly use XDebug under Emacs. Configuring Eclipse will also help me help my coworkers, who tend to not be big Emacs fans. (Sigh.)

So here’s my current setup:

  • A Linux server environment in VMWare, so that I can use all the Unix tools I like and so that I don’t have to fuss about with a WAMP stack
  • Samba for sharing the source code between the Linux VM image and my Microsoft Windows laptop
  • XDebug for debugging
  • Eclipse and PDT for development

I like this because it allows me to edit files in Microsoft Windows or in Linux, and I can use step-by-step debugging instead of relying on var_dump.

Setting up Samba

Samba allows you to share folders on the network. Edit your smb.conf (mine’s in /etc/samba/) and uncomment/edit the following lines:

security = user

[homes]
   comment = Home Directories
   browseable = no
   read only = no
   valid users = %S

You may also need to use smbpasswd to set the user’s password.

Xdebug

Install php5-xdebug or whatever the Xdebug package is for PHP on your system. Edit xdebug.ini (mine’s in /etc/php5/conf.d) and add the following lines to the end:

[Xdebug]
xdebug.remote_enable=on
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1
xdebug.remote_connect_back=1

Warning: this allows debugging access from any computer that connects to it. Use this only on your development image. If you want to limit debugging access to a specific computer, remove the line that refers to remote_connect_back and replace it with this:

xdebug.remote_host=YOUR.IP.ADDRESS.HERE

Eclipse and PDT

I downloaded the all-in-one PHP Development Toolkit (PDT) from http://www.eclipse.org/pdt/, unpacked it, and imported my project. After struggling with Javascript and HTML validation, I ended up disabling most of those warnings. Then I set up a debug configuration that used Xdebug and the server in the VM image, and voila! Line by line debugging with the ability to look in variables. Hooray!

2011-05-31 Tue 17:37

  • Chris Calip

    All done without much unix foo skills needed:
    http://drupal.org/project/quickstart

  • http://sachachua.com Sacha Chua

    Oooh, even cooler. Thanks for sharing! =)

  • Droplet

    The only down side is transfer small files via samba is critically slow. (Using long time to index a new project in Eclipse/Netbeans)

  • http://wunderkraut.com Florian Loretan

    We use a similar setup, with the main difference being that the files are stored on the host system and shared with the guest system using VMware’s shared folders. We use OS X but it should work on Windows too. This has the advantage of having no noticeable slow down (even when using Eclipse!).

  • Droplet

    @Florian Loretan,
    Thanks for the sharing. I’m using Virtualbox and will do a test with VMware. Using shared folders in Virtualbox (root directory of Apache) will make LAMP slowly down.

  • mikeytown2

    I use andlinux. Here is a guide on how to do it.
    http://drupal.org/node/505974

  • Drupal Theme Garden

    Very interestin setup and approach.

    Why not a simple dual boot host (win/lin)?

    • http://sachachua.com Sacha Chua

      I like Microsoft OneNote and Autodesk Sketchbook Pro too much, and dual-booting can be a hassle. =)

  • mikeytown2

    One thing I forgot to mention is if you have multiple boxes Synergy is the way to go
    http://synergy-foss.org/

  • http://www.myplanetdigital.com/blog Patrick Connolly

    Dude, you should definitely ditch VMWare and Samba and check out Vagrant ;)
    http://www.vagrantup.com

    It’s multiplatform, and abstracts away all the complicated stuff (port forwarding, ssh, shared folders, etc.) and makes it so it’s literally one command to boot up and provision on the spot. Oh hey, and it gets around the shared folder slowness issue by running on an NFS host-only network if you prefer, and again, that’s as simple as editing one line in the config file. Guaranteed you won’t go back!

  • http://sachachua.com Sacha Chua

    Ooooh, that looks awesome indeed. I may try it for my next project. Bookmarked!

    Have I mentioned how much I like writing about ways I’ve solved something, particularly when people point out better and better ways to do things? =D Really, I don’t know why people think blogging is a time-waster…

  • http://www.bugsbane.net ramon

    Yehey! I’m not unique in calling you dude..

    Bookmarked Vagrant. I definitely will try that out. BTW: Doesn’t Eclipse come with keyboard mappings for Emacs? that way you won’t have to forgo your ‘muscle memory’. Forgive the comment if it’s littered with :wq’s.

    OK. Quick question – not about this post (since I my setup is pretty much the same, with the exception of VMWare Tools instead of SMB)…

    I was sent an RFP for an auction-site type project with some CMS mixed in. Rather than built it out using CakePHP or some other framework – I thought I’d go with Drupal 7 + DRUSH and build out the auction components in a module. (Views, I guess).

    What do you think? It may shave a week in development since I won’t have to bother with the CMS portion. But… I don’t know Drupal that well. Let me know please. I need to respond by Monday. Thanks.

  • http://sachachua.com Sacha Chua

    There are auction modules for Drupal, too. =) Tell you what – spend a weekend trying out Drupal, and you’ll have a better idea of how easy you’ll find it to implement. You might be surprised at how much you can cobble together from existing modules.

  • http://www.bugsbane.net ramon

    ok. Sounds like a challenge. I hope you’re able to get dry after that bike-ride.

    … but… an auction module for drupal??? hmmm… ok. baby steps. let’s crank…

    OH WAIT. quick question: when you got your vmware image, did you build it out yourself or get a public-domain one? if it’s the latter, can you let me know which? I do have a couple of ubuntu (8.x and 10.x) images for I want to use CentOS 5.6 for this project.