Vagrant is quickly becoming the standard resource for local development environments, and it works particularly well for WordPress. You may be using MAMP for your local dev environments which could be a great solution, depending on your preference. This is a different format from my usual WordPress QuickTips but this one is a little more complicated in the sense that it requires a few snippets of code to copy and paste. I feel this one would be best produced as a step by step tutorial.
What is Vagrant? Why should I care?
There are some downfalls to MAMP that are solved by using Vagrant. The main reason I stray away from MAMP is due to it’s instability considering it essentially turns your computer into a server. Running a simple update to your operating system could break the MAMP configuration causing you to start all over again. Vagrant solves this issue by creating a virtual server utilizing VirtualBox, meaning that any changes made to your local computer have no effect on the VirtualBox instance while allowing your access to the file structure locally the same as you would using MAMP. The other big benefit of Vagrant is the standardization of your dev environments. Vagrant files essentially create an image of a server, installs php, configures mysql, installs WordPress on that image, and maps the file structure with a single command. This ensures everyone on your team is working with the same configuration every time.
Alright I’m sold show me how already!
You’ll need two things installed on your computer before proceeding: 1) Virtualbox – https://www.virtualbox.org/wiki/Downloads 2) Vagrant – https://www.vagrantup.com/downloads.html Once you have installed the required resources you will need a Vagrant image to run off of. There are many out there but my preference is called Varying Vagrant Vagrants https://github.com/Varying-Vagrant-Vagrants/VVV Move the downloaded zip folder to a directory you’d like to house your files. (I keep mine on my desktop) and once that is completed unzip the folder.
From here out you will need to be in a terminal application.
CD into the VVV-Master Directory and run the following command:
You will see errors which are normal. Just let it run through them. It will take some time for Vagrant to gather all of the resources so depending on your computer’s speed and internet connection it could take some time. Once the vagrant up has completed you will need to edit your hosts file. Run the following line:
sudo vim /etc/hosts
You will be prompted for your computers password and once you are in the file move your cursor to the bottom of the file and hit the ‘I’ key. Paste the following line into the file:
192.168.50.4 vvv.dev local.wordpress.dev local.wordpress-trunk.dev src.wordpress-develop.dev build.wordpress-develop.dev
That’s it! You now have Varying Vagrant Vagrants installed and running!
You can now access your sites at the following url’s Main dashboard: http://192.168.50.4
http://local.wordpress.dev for WordPress stable (www/wordpress-default)
http://local.wordpress-trunk.dev for WordPress trunk (www/wordpress-trunk)
http://src.wordpress-develop.dev for trunk WordPress development files (www/wordpress-develop/src)
http://build.wordpress-develop.dev for a Grunt build of those development files (www/wordpress-develop/build)