XAMP vs Vagrant – subjectively on virtualization

With some recent experience regarding Vagrant I thought there are a few things worth sharing. As probably many others, for most of my PHP / MySQL projects I would use XAMP running on my pc, in many cases just organising projects into subfolders of localhost. Problems arise when the default configuration is not enough, and particular projects may require different incompatible settings. In such cases Vagrant seems to be an interesting option. In my case what convinced me to try it was XAMP becoming very sluggish with configuration changes being made every time something different was needed for my project. At some point I was not able to determine what is causing such poor performance.

What is Vagrant about?
Comparing Vagrant with XAMPP is not really a comparison of which is better – as these are completely different things, with different features and enforce different methods of work. The reason this comparison is made is to highlight what can a solo developer expect when deciding to use one or the other to run a server on their local machine.
Vagrant handles updating and configuring virtual servers, it typically uses Virtual Box for virtualization. Together with tools like PuPHPet setting up a virtual server running on a Linux distribution of your choice is really simple. Because everything is contained within a virtual machine it does not matter what OS are you working on, you can also replicate the same server on any other pc. This feature might turn out really important if you are working on a team and want to keep the envoirment consistent between all co-workers.
What’s more, a virtual server, once turned off does not have much impact on your system, regardless of the configuration and libraries you enabled for the project you were working on, everything is contained within a virtual machine, commonly called a “box”.

This sounds really good, so what are the down sides?
Not everything is as simple as it may look.  As soon as you turn on your IDE and want to start working you may hit some issues. In my case Netbeans is the IDE, it has a nice Vagrant plugin which alows you to manage your virtual machines, but it allows only basic integration. One of the things you might want to start with is to get xdebug working with your project. This will require enabling xdebug through SSH on your virtual server. You probably never had to use SSH with XAMPP. You will also need to map your projects path to the directory on your server. All can be done, but takes a bit more effort than setting it up with XAMPP or the likes.

Next step?
Let’s get PHPUnit and run some tests with Netbeans… no, no luck here. At the moment there is no plugin for Netbeans enabling PHPUnit testing to be run on an external server. You need to SSH into your virtual machine and type commands to run your tests – not very convenient. You can write a batch file to do that, but getting support for features like code coverage does not seem possible.
What seems easiest in this case is to install XAMPP for the purpose of generating and running tests – simple but brings back the issues which Vagrant was supposed to solve (platform independence).

Trying to share on your local network?
Again extra effort is needed here – this time it will be editing the Vagrantfile (a file responsible for the server configuration) to add an extra network interface, so that the virtual machine becomes visible outside of pc it is running on. On my first attempt this wasn’t as simple as I hoped it would be.

Overall Vagrant and virtualization certainly do seem the right direction to go, it has allowed me to avoid setting up servers directly on my system. But due to the nature of running everything within a separate environment, outside of your system, virtualization will cause extra complexities which may outweigh the benefits – IDE integration is certainly one thing which will cause a bit trouble, libraries such as phpUnit mentioned above are simply not directly accessible for the IDE.
Finally I must say switching to Vagrant has resolved my performance problems with XAMPP, and after a few months of usage I have not decided to go back.