Things That Matter Most

Things That Matter Most

  • Home
  • Business
  • Faith
  • Technology
  • Politics
  • Creative Writing
  • Email
  • GitHub
  • RSS
  • Twitter

Powered by Genesis

Vagrant and Windows

March 5, 2014 by Eric

I often brag about the fact that I’ve dumped heavy tools like XAMPP in favor of Vagrant.  I’m quite proud of this accomplishment, and I urge every other developer I meet to look into Vagrant.

Unfortunately, setting up Vagrant proves to be a bit trickier on Windows.  I admit, I struggled a bit with it myself when I first set things up.

A few days ago, though, I decided to swap out my aging Windows machine for a new one – so I have the opportunity to set up Vagrant again, from scratch, on Windows.

Let me walk you through it.

Prerequisites

I set up a handful of things on every Windows development box I used.  For the purposes of Vagrant, though, there are two tools in particular you’ll want handy.

First, download and install Git.  You’ll want to download the real command-line tool itself, not a custom GUI.  When you install, you have the option to add Git and its Linux-style command line tools to your system Path.  Do this!

If you already have Git installed, or you forgot to select this option upon installation, you’ll need to add Git’s /bin directory to your Path manually.  I’ve already written instructions for how to do just that.

Screenshot 2014-03-04 17.21.50Second, you’ll want to set up an elevated command prompt shortcut – this isn’t a prerequisite for installing Vagrant, just a handy tool to have around.

I usually set up a custom shortcut in C:/Tools that launches an elevated command prompt.  I also configure it to use CMD + ALT + HOME as a shortcut key so I can launch a new elevated prompt whenever I need one.

Installation

The installation process is fairly straight-forward from this point: you’ll have to download and install 2 things:

  1. VirtualBox (4.3.8 at the time of this writing)
  2. Vagrant (1.4.3 at the time of this writing)

There’s nothing fancy to it, just install both and then move on with the process.

Configuring Your Environment

I use Varying Vagrant Vagrants (VVV) as a project template for my local environment.  If you’re using the same this will help – if not, skip to the next section.

Use Git to clone VVV to wherever you want your projects to live on your hard drive (I keep mine in C:\Projects).  If you have existing projects to pull in to the environment, you can drop them in custom subdirectories of /vvv/www and configure the Nginx rules for the sites.  I’ll leave that exercise for later. 1

The next step is to turn things on.  Launch your elevated command prompt 2 and run vagrant up.

Voila!  You have a local environment!

Working With Vagrant

The biggest reason we installed Git (and set it in our Path) in the beginning was to grant access to a *nix SSH tool.  You can now log in to your vagrant box with a simple vagrant ssh.  Without this tool, you’d need to download, install, and configure a tool like puTTY to access the system.

I like simplicity; vagrant ssh from an existing prompt is easier.

You’ll also likely want the ability to work with your MySql databases from something other than the command line.  Personally, I use MySql Workbench. 3  Once installed, it can connect to a database server over an SSH tunnel and run commands remotely.

Screenshot 2014-03-04 17.38.46

If you’re using VVV, then your SSH username is “vagrant,” your SSH keyfile is stored in C:\Users{your name}.vagrant.d\insecure_private_key, your MySql username is “root,” and your MySql password is “root.”  Set up all of the above and you’ll have a solid connection to your database from something other than the command line.

What’s Left?

Vagrant is just one tool I use to make local development easier on Windows.  Luckily for me, it also makes web development easy on Mac, too.

With the exception of the elevated command prompt above, all of the software I’ve listed in this article are cross-platform.  I use the exact same tools on my Mac that I use on my PC.

In addition to the above, I also have a standardized IDE, test suite, and command-line helper tools that make writing code easier, faster, and less error-prone.

What tools would you add to the above to help new developers get started, regardless of platform?

Notes:

  1. If you’re stuck, look at the default sites and configuration that ships with VVV and build your custom site configs off that. ↩
  2. An elevated prompt isn’t strictly necessary here.  But I usually spin things up and then use the same prompt to run tools like Node and Grunt while developing.  Using a single prompt for all is just faster. ↩
  3. It’s conveniently free, open source, and built by the same people who build MySql in the first place. ↩

Filed Under: Technology Tagged With: development, setup, Vagrant

Like what you’re reading?

Consider pitching in to help cover the costs of maintaining this site and keeping my work 100% ad-free.

Close×

Comments

  1. NotDior says

    July 22, 2014 at 7:56 pm

    I’ve got this to install however when I try and SSH thru git I keep getting:

    VM Must be running to open SSH connection. Run ‘vagrant up’ to start the virtual machine.

    I can SSH just fine with putty, but not Git. I’ve got my path set to have the bin of the git install and I’ve got the tools installed

    Any ideas?

    • Eric says

      July 23, 2014 at 1:52 pm

      Not sure why that’s failing. I followed the steps outlined here on multiple machines without any issues. If you were SSH-ing in to a remote server I would recommend placing your keys in both Git’s .ssh directory and the one in your local user profile. With Vagrant, though, that shouldn’t be necessary.

      Obviously Git’s SSH tool is working from the command line if you’re getting that error (rather than Windows failing to recognize SSH). I’d recommend asking around the Vagrant community for extra help since this is a bit beyond me.

  2. Sumit says

    August 7, 2014 at 2:12 am

    I recently switched to Virtual MAchines as well. I use the same setup as you do with the help of puppet (puphpet.com).

    The vagrant up process seemed to change though. I’m trying to setup a new VM right now and i can’t figure out the IP of the VM to access it via the browser. Now i have to SSH into it and check the IP and I’m stuck there.

    Do you have any info on how to find out the IP of the VM?

    • Eric says

      August 7, 2014 at 7:27 am

      If you use the Vagrant Hostsupdater plugin, your hosts file will automatically be updated to include the dynamic IP. I have a version I modified specifically to use the dynamic IP generated by Hyper-V on GitHub.

  3. Tracee Murphy says

    January 19, 2015 at 12:04 pm

    I have worked on setting up VVV over the last few days w/o any success. I’ve tried piecing together different tutorials, following the steps that are common between them and include steps that seem necessary, but left out in other tutorials.

    I’m hoping you can help me fill in the gaps. Here is some background info:
    OS: Windows 7

    Installed:
    Git and Github for Windows (I’m using Git Bash for my CLI)
    MySQL Workbench + the two libraries
    VirtualBox and the Ext. Pack
    Vagrant
    Cloned VVV

    First VVV Install:
    Followed the First Vagrant Up instructions without any further steps in between. Which is where I think I went wrong. It took a while to get a local host, but after typing in 192.168.50.4 several times it finally loaded and I had the page with all the links and WP links; however, I cannot connect to any of the WP links such as local.wordpress.dev. When I try Fix connection problems, Windows gives me this alert:

    The device or resource won’t accept the connection.
    The device or resource (local.wordpress.dev) is not set up to accept connections on port “The World Wide Web service (HTTP)”

    At this point I have uninstalled/reinstalled VBox, Vagrant, and the two plugins. I want to make sure I have done all the necessary work before I clone VVV again.

    So what am I missing? I need a complete step by step tutorial from installation to starting new WP environments for each new website. I understand VVV is not for the faint at heart, but I have a strong will and determination to learn this as well as great at following good directions.

    Your help is much appreciated!

    • Eric says

      January 23, 2015 at 9:39 am

      I’ll see what I can do to get you a full tutorial with VirtualBox. That said, on Windows (particularly if you have Windows Pro) I highly recommend Hyper-V as an alternative and the steps on this blog are exactly what I did to set up both of my machines.

      • Tracee says

        January 23, 2015 at 11:17 am

        Actually, I figured it out. I had to reset my hosts file. It was easy with the Fix It wizard through Microsoft.
        http://support.microsoft.com/kb/972034/en-us

        I have since installed MySQL Workbench, VVV Site Wizard and VVV Dashboard. Thinking about installing WP-Theme Review VVV, but I don’t want more than what is necessary especially during this “learning stage”. Now that I have a local WP, do I work with themes, child-themes, plugins, etc. in the same way I do when I am logged into a live site?

        I recently graduated with an AAS in web design/development. We are taught code, design, and internet marketing, but they don’t teach local development, test servers, and how to put it all together in a practical way. I have a few WP sites that need updating and a practice site to experiment with. Eventually I want to build my own WP themes.

        I’ll definitely read any recommended tutorials and check out Hyper-V. I appreciate you taking time to reply–Thanks!

        • Eric says

          January 23, 2015 at 11:36 am

          I was wondering if that would be the fix. I usually recommend everyone install the Hosts file updater plugin for Vagrant. It will automatically update your hosts file when you start the VM, then clean out its new entries when you turn things off. Just run:

          vagrant plugin install vagrant-hostsupdater

          This installs and configures the plugin. The only other thing I recommend at that point is to run your console (whether Git Bash or CMD) as an Administrator so the tools have access to work their magic.

          • Tracee says

            January 23, 2015 at 12:16 pm

            I installed hostsupdater, triggers, Git Bash, and run as Administrator prior to the first vagrant up. None of that worked until I reset the hosts file.

  4. Noah says

    January 23, 2015 at 10:31 pm

    Everything is working great from the instructions for me – except things seem to be getting stuck here:

    ==> default: Waiting for machine to boot. This may take a few minutes…
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying…
    default: Warning: Connection timeout. Retrying…
    default: Warning: Connection timeout. Retrying…
    default: Warning: Connection timeout. Retrying…

    This just keeps going and going until the standard error after timing out. I see the VM in running in VirtualBox – oddly though (maybe?) ‘Show’ is grayed out in VirtualBox – so I can’t even see the VM at the console level. So there may be issues with the VM coming up correctly on the VirtualBox side? I’m not really sure. Any information I can provide that may be helpful to troubleshoot?

    Thanks for any advice!

    ***So – I changed the image from ‘precise64’ to ‘precise32’ and it came up just fine. I am running a 64-bit Windows 7 installation. So .. that seems a bit odd?

    • Eric says

      January 24, 2015 at 11:22 am

      That is a bit odd. But the fact that you’re still on Precise makes me wonder how old of a copy of VVV you have – the current setup loads Trusty (64-bit), which is a newer version of Ubuntu (14.04 LTS).

      • rubidot says

        May 30, 2015 at 8:35 am

        In case someone else comes looking for the solution:

        I had the same problem. I had to enable virtualization support in my BIOS to get this working.

  5. aloxin says

    October 14, 2015 at 6:32 am

    Thanks for the post. I was using this instruction for installing vagrant under Windows 8.1 – http://sysadm.pp.ua/linux/sistemy-virtualizacii/vagrant-begin.html. Could you please give some example, how can I create couple machines with different IPs using Vagrantfile ?

  6. Adi says

    March 31, 2016 at 8:20 am

    Hi! Nice article! I have been using Vagrant and Git and am able to function without any real issues. I have created an instance of samba server so that I can access the virtual drive from Windows. I am using Git command line for all git related operations however, I would like to know if there is a way to implement a GUI like TortoiseGit. I have TortoiseGit installed on my system but the problem here is that the virtual drive does not show the .git folder due to which the GUI is useless. The .git folder is visible when I access the virtual box through vagrant ssh command line but it remains hidden when I access the virtual drive through windows. Is there a way to somehow make it visible on windows so that I can make use of the GUI for Git related actions. Sorry for the long description but would like your suggestion if you get what I am saying! Thanks in advance! 🙂

  7. Vinay BG says

    December 20, 2016 at 11:55 pm

    Hello,

    Please help.

    I have installed an vagrant – 1.9.1 & VirtualBox – 5.0.14 on Windows 8.1 machine
    From my cmd prompt, when i run a “vagrant up” command i get the below error:

    e:\HashiCorp\Hands_on_ansible>vagrant up
    There is a syntax error in the following Vagrantfile. The syntax error
    message is reproduced below for convenience:

    e:/HashiCorp/Hands_on_ansible/Vagrantfile:10: formal argument cannot be a constant
    config.vm.define “Test1” do |Test1|
    ^
    e:/HashiCorp/Hands_on_ansible/Vagrantfile:15: formal argument cannot be a constant
    config.vm.define “Test2” do |Test2|
    ^

    Here is my vagrant file:

    # -*- mode: ruby -*-
    # vi: set ft=ruby :

    # All Vagrant configuration is done below. The “2” in Vagrant.configure
    # configures the configuration version (we support older styles for
    # backwards compatibility). Please don’t change it unless you know what
    # you’re doing.
    Vagrant.configure(“2”) do |config|

    config.vm.define “Test1” do |Test1|
    Test1.vm.box = “ubuntu/trusty64”
    Test1.vm.hostname = “Test1”
    Test1.vm.network “private_network”, ip: “192.168.0.103”
    end
    config.vm.define “Test2” do |Test2|
    Test2.vm.box = “centos/7”
    Test2.vm.hostname = “Test2”
    Test2.vm.network “private_network”, ip: “192.168.0.105”
    end

    end

    Thanks in advance.
    Vinay BG

    • Vinay BG says

      December 20, 2016 at 11:58 pm

      Actually the arrow is pointing near the pipe symbol:
      |Test1|
      ^
      |Test2|
      ^

    • Eric says

      January 5, 2017 at 2:18 pm

      Sorry, but I don’t offer support from the blog.

  8. chaos/dessper says

    January 26, 2019 at 11:14 pm

    Your instructions make the whole process seem incredibly easy. Blithely you say “Use Git to clone VVV to wherever you want your projects to live on your hard drive (I keep mine in C:\Projects). If you have existing projects to pull in to the environment, you can drop them in custom subdirectories of /vvv/www and configure the Nginx rules for the sites.” and “Voilla!” 24 Hours later and I’m smashed by the experience.
    Ridiculous noob, I hear you say. Would it have killed you to take the trouble to extend your lofty wisdom a little further down to where we all struggle in the depths of ignorance? We’re trying. We really are. We just need to know those bridging skills between nothing and requiring a graduate degree. There’s a gulf in between where we’re plummeting to our dooms.
    There are a lot of posts here from people who’ve followed your smooth, brief instructions. Hey it looked great reading it. Could you not have anticipated the strife?
    Rotten ingrate, I hear you say. Yeah well I’ve been at it all day yesterday and overnight and now it’s the evening of the following day and still in chaos, still no local host to run wordpress. I wish there was more in your post to guide me.
    Idiot, I hear you say. Well nope actually. Just need a little bit more detailed instructions.

    • Eric says

      January 27, 2019 at 6:29 am

      For the record, I write articles like this explicitly to help people who are stuck on issues. I published this almost 5 years ago to answer specific questions that people had asked me at the time. It’s likely quite dated since then.

      Instead of assuming I’d talk down to you, maybe take a different approach and outline where you’re getting stuck. Need help using Git on Windows? I wrote about that, too.

      I wish there was more in your post to guide me.

      Sure. Let me know where you’re getting stuck and I’ll do what I can to help. Just assuming I’d ignore you isn’t going to help either of us.

About Me

Eric is a storyteller, web developer, and outdoorsman living in the Pacific Northwest. If he's not working with new tech in web development, you can probably find him out running, climbing, or hiking in the woods.

Get the newsletter