For the last several months, I’ve been using Visual Studio Code for all my PHP projects. I started using Better PHPUnit to run my unit tests because it has a quick keyboard shortcut to run a specific unit test from inside Code. I just set Better PHPUnit up on a new computer I forgot a couple of hoops I had to jump through in order to get it to run inside my Vagrant VM. This post is documentation so I won’t forget and that will hopefully help someone else.
The first step is to determine the name of the SSH user that Vagrant uses to connect through SSH. This is done using the
vagrant ssh-config command from your host computer.
This is a “duh” statement but the “User” line is what we’re looking for.
The next item we need to know is what IP address our VM is using. This can be found in our Vagrant file in a line that looks like the one below.
Next we need to open our settings.json file inside Visual Studio Code and add the following lines:
Now this might work but you’ll be prompted for a password each time which is super annoying. To make this process easier I got the value of my public key on my host computer:
And then I append it to the authorized_keys in my VM: