Download Slides: WordCamp Chicago 2013 – “Hi WordPress, Meet Vagrant”
Talk Goals
I want each one of you to leave this talk amped up to use Vagrant for WordPress development.
I know this sounds crazy because I haven’t even told you what Vagrant is all about yet, but I’m really not going to be satisfied until the WordPress community starts to forget what the acronym LAMP even stood for in the first place. As we’re going through this together, I encourage you to imagine ways that Vagrant can fit into your development work flow, how it may have helped you solve problems faster in the past, and how it’s going to make you solve problems faster in the future.
This Post Goals
In the past I’ve used the follow up post with slides to provide a large amount of context for those who came through a bit later. That ends up being a massive dump of information, so I’m going to use this post to highlight a few of the key concepts that I’m hoping everybody took away from the talk. As time progresses, there will be several places on my site to point you to for information on using Vagrant with WordPress.
Vagrant & Magic
“any sufficiently advanced technology is indistinguishable from magic.” – Arthur C. Clark
When I sat down and used Vagrant for the first time, it was magic. I had no idea what was going on, but it was going on and I liked it. And it makes sense that it seem like magic at first because really cool things happened without much effort.
“Witchcraft to the ignorant, …. Simple science to the learned” – Leigh Brackett
Over the last 7 months I’ve gotten deeper and deeper into what Vagrant is and what it means for development and I can now appreciate it as a piece of advanced technology with many possibilities for expansion and use rather than the magic it started as.
This is what we’re going to cover. The transition from magic to approachable advanced technology. I’ll walk through and explain why and how you should start using Vagrant to manage your development environment when creating plugins and themes for WordPress. Together we’ll demystify things a bit so that you’ll immediately want to uninstall XAMPP or MAMP and Vagrant becomes something you’re excited to start using.
30,000 Feet
Your computer is a beautiful lawn. It starts off well manicured, with nicely defined paths around kept gardens that have some wrought iron fencing around them, helping to keep things clean. There may even be a couple police officers hanging out to make sure that nothing bad is going on.
A server is a large, beautiful beach connected to the ocean. So many possibilities for digging holes and building sand castles and creating complex moats for waves to come through to visualize how well your sand castle was constructed.
XAMPP/MAMP is a small sandbox in your yard. You have an old tire, maybe a pail. Some shovels and a few rocks that you can play with. You can test out some structures in the sand if you’d like in preparation for the big beach day. If you get real fancy, you might even drag over a hose to spray down the sand castle just to see what happens.
Installing server software directly on your computer is like having a load of sand delivered to your house and dumped on your front lawn. You can probably do a bunch with it, lay out as if it was a beach and build a sand castle or two, but that well manicured look you started with will go away and over time it’s going to become harder and harder to keep track of where all that sand went.
Are you ready for what Vagrant is?
Vagrant is an extreme sandbox. You can do whatever the heck you want with a beach worth of sand, moving it around and building and getting in trouble. If you flip a front loader or a bulldozer goes crazy and starts running things over, no big deal. Hit the reset button and you get to start over.
And when you’re done for the day, only one command stands between you and the personal computer that remains a beautiful garden.
Ground Level
Now that we have a picture of what we’re shooting for, let’s back up again and start over on the ground.
Where did the WordPress community come from?
A World of LAMP
For quite a while in the WordPress community, LAMP was the answer. Many people still consider it to be a perfectly fine answer. All you needed was some sort of LAM stack – Linux, Apache, MySQL – with a PHP, Perl, or Python tossed on. Big applications and web sites could be developed this way.
What was great about the LAMP stack is that it became pretty reproducible on our local machines. We saw this earlier with our hand raising exercise. Almost every WordPress developer has probably used some form of XAMPP, MAMP, or WAMP to manage their local environment. This focused sandbox environment goes a long way when building basic WordPress themes or plugins for customers.
That said.
Over time, as a community, we get better at this stuff.
That’s our goal. We don’t strive to do the same, we strive to do better. This is how technology works, and this is what’s required of us to use that technology in better ways.
Breaking Up With MAMP
https://twitter.com/jeremyfelt/statuses/278262418877059072
I got a couple replies to this tweet, one of them asking if I had looked into using Vagrant. I had seen Vagrant mentioned a few months earlier but hadn’t taken the time to grasp what was going on and had kind of dismissed it as something that would be nice to learn, but that wasn’t for me. This time, faced with installing Nginx locally and destroying my beautiful garden, I decided to give it a another chance.
Life changed.
“There’s life before Vagrant, and life after Vagrant. The former ain’t pretty.” – @danielbachhuber
What is Vagrant?
Vagrant is open source software for “creating and configuring lightweight, reproducible, and portable development environments.”
These lightweight, reproducible development environments exist on your computer through Virtualization.
Virtualization is “the facility that allows multiple operating systems to simultaneously share x86 processor resources in a safe and efficient manner.”
Virtualbox is software that provides virtualization and is “installed on an existing host operating system as an application; this host application allows additional guest operating systems, each known as a Guest OS, to be loaded and run, each with its own virtual environment.”
A great part about both Virtualbox and Vagrant is that installers for each are available for Mac, Windows, and Linux. This means that rather than juggling various MAMP/WAMP/XAMPP/LAMP acronyms, we can all be on the same base platform.
What does this combination let us do?
Allows a guest machine to boot as a sandboxed environment inside a host machine using a combination of a base box and some sort of provisioning.
Getting Started
Let’s walk through the step by step of getting a base.
- (Install Virtualbox) Download and install Virtualbox
- (Install Vagrant) Download and install Vagrant
- (vagrant init) Create and then navigate to an empty directory on your computer via the command line and type `vagrant init`
- This creates a `Vagrantfile` file in this empty directory that describes the virtual machine you are looking to start.
- (edit Vagrantfile)
- In this file we tell the machine what base it should load, what network information it should use, and then how it should be provisioned. For the first go, we’ll leave just a box specified.
- (vagrant up) Type `vagrant up`.
This is the magic part. At this point, through no additional interaction, an empty Ubuntu box is available for my use on my computer. All I need to do is go to a command prompt, type `vagrant ssh` and I’m in. From there I can do anything that I would normally do with a fresh server instance.
As I’m biased to the stuff we do at 10up, I’m going to use an example of shell provisioning taken from our open sourced Varying Vagrant Vagrants.
This Vagrant configuration is an opinionated attempt to mimic a fairly common server configuration used for performant WordPress projects. We’ve put quite a bit of work into this and have had a great number of contributions from the community already, so I really would recommend grabbing this and using it to get your feet wet if not to use as your daily development environment for WordPress projects.
I uninstalled MAMP shortly after creating this and haven’t looked back.
And now, only a couple minutes stand between my beautiful lawn and having an extreme sandbox up and running. In fact, if I power off the virtual machine without destroying it completely, we’re looking at an extremely short start up time whenever I want to dive in.
Why?
Why should you develop in an environment that matches production?
Over time, as a community, we get better at this stuff.
To make and then meet expectations. There are a variety of issues that can arise between various PHP versions and large differences between how various object caching methods store and expire data. In fact, with a basic LAMP stack using MAMP or XAMPP it may not be entirely obvious how to begin troubleshooting any type of caching issue with WordPress and while APC and Memcached often act the same, it is nice to know that when an issue arises somewhere in your code that you don’t have to question the development environment being used.
During the town hall yesterday, Matt told all of us that he learned to code because of WordPress. I’d venture to guess that quite a few of us also learned to code because of this.
And look at where the community has come since then. We’ve gotten better at UI and UX over the last few years. Accessibility and language translations are both major focuses that have excellent contributors. We have talented business people driving the use of WordPress throughout all types of industries.
Not only does Vagrant help us become better developers by encouraging carelessness and a willingness to experiment with our development environments.
Vagrant allows us to start enlisting devops people into the community. So many problems have been solved in technology by devops already. Think of the server problems that Twitter had when they were growing to scale. Devops solved that. Google and Facebook have both scaled to billions of page views. Devops solved that. An amazing team at Automattic is working constantly to increase the abilities and the stability of the WordPress.com environment. Devops solved that.
Devops can also help to continue WordPress’s growth as a CMS and an application platform. And Vagrant provides a vessel for this to happen.
Imagine working for a customer that is going to host their site on WPEngine and knowing with absolute confidence that the theme you created locally will work without issue.
Or knowing that customers using default WordPress installations on Dreamhost or Bluehost will have not troubles using the plugin that your about to publish to the repo.
And I should stress that while Vagrant is very much going to replace MAMP for you, it is not a MAMP replacement.
Because that’s not what you should want. Instead of one environment restricted to technology that the community covered years ago, you should want a flexible environment that can adapt seamlessly to the technologies that the community must work with today.
Links
Check out the open source Vagrant project at github.com/mitchellh/vagrant.
Check out a provisioned Vagrant setup at github.com/10up/varying-vagrant-vagrants/
Read through the material I’ve posted on Vagrant over the last several months on jeremyfelt.com
And ask questions. Drop an issue on the VVV repo, or send me an email or a tweet @jeremyfelt.
The only requirement for your mention to be recognized is a link to this post in your post's content. You can update or delete your post and then re-submit the URL in the form to update or remove your response from this page.
Learn more about Webmentions.