• Home
  • blog
  • Containerized PHP Development Environments with Vagga

Containerized PHP Development Environments with Vagga

It happens to all of us once in a while.

We clone a project, and then we try to run it. However, something doesn’t work.

Broken car image

It may be our version of NGINX or Apache. It might be that npm isn’t doing something right. Maybe the project needs an extension, and we don’t have it installed, and now we have to build the extension from source because the dependency does not exist in the repositories for our distribution. No matter the reason, the more complex the setup, the higher the probability of failure.

When I first got to know Vagrant, it was like heaven: there was finally a chance to break free of the shortcomings of Windows, while not having to deal with the accessibility issues present in Linux.

I was happy. For a while. And then the limitation of having virtual machines as development environments hit me. Hard.

Imagine this scene: it’s 4:30 PM. The developer working on the Asterisk system has left the company. Something in the payment logic (written in PHP using the deprecated PHPagi project) doesn’t work, and you have to fix it, fast. You and a colleague have been urging everyone toward a service-oriented architecture, and so, to be able to bring up a development environment, you have to have the following:

  • An instance of the Asterisk machine which handles calls. It must have Asterisk and PHP 5.5.X running.
  • An instance of another Asterisk machine which actually handles the payment. Since the bank you are working with has a policy of closing all access to its APIs coming from outside the building, this is a copy of the machine above, but with different code running on it.
  • The PHP back-end API that does the heavy lifting, written in PhalconPHP.

So you tape together some puppet scripts to provision your boxes, you vagrant up three machines, and prepare to enter the zone!

If this was a movie, the scene would zoom into your host machine at this point, dramatically showing the large amounts of data traveling at light speed between different parts of your system, filling up your memory and CPU, and then coming to a grinding halt. However, since this is not a movie, suffice it to say that your development machine might be able to handle one or two boxes with 8 GB of memory on Windows, but when the third machine comes up, your development environment is going to be slow to the point that you will not be able to launch an IDE.

Of course, you are very clever and resourceful, and know how this stuff works. You’d lower your memory and CPU in your vagrantfile, but that leads to Asterisk complaining about a small memory size, and when you manually call your phone system with a softphone (equivalent to a browser in the online world) to test it, the audio breaks up and distorts. You need a lot more memory than you already have, and you don’t have access to it, and now it’s 10:30 PM.

So what happens to you?

Nothing good. You fail to fix the problem that night, have to deal with an angry boss who doesn’t have the technical background to understand what you are talking about, come back to work tomorrow, tell two of your colleagues to run one of the needed machines from the list above on their own machine, and you string these virtual machines together to get the code to run. Oh, and let’s not forget the problems you have with building all the dependencies because they weren’t documented anywhere. That’d just be too ugly.

But all problems give rise to new opportunities: enter Vagga, a way to set up your project and its dependencies (usually) with a single command, with far less resource usage.

What is Vagga?

Vagga is a container engine, like Docker, which has been created to make it easier to build development environments. Since it is a fully-userspace container engine, it loads much faster than Vagrant, takes much less memory, and allows you to do awesome things like run your application in different environments in just a few seconds, without waiting for a completely virtualized machine to boot up.

Vagga is in beta stage right now and it is likely you might face some problems, but the concept shows great promise, and that’s why we have decided to take it for a spin.

Continue reading %Containerized PHP Development Environments with Vagga%