The vagrant share command is totally underused and working in a remote company it’s also totally necessary. Nearly everyday I’m asked to troubleshoot a piece of code or help figure out a bug. Usually I need some context in order to help so I say “can you share your screen” or “would you mind pushing that up to staging and I’ll have a look at it later”. That’s just no good because it creates a time gap where I can’t help them. And oftentimes by the times I get around to taking a look they’ve already given up or went another route. That just sucks and there has to be a better way right? Well, there is and it’s called
vagrant share. But there is one issue and that is by default it shares the default configuration for the VM which working in VVV is the default screen which isn’t very useful in debugging a site. But there is hope yet.
Luckily with the vagrant share command you can specify a port as one of the flags. So this got me thinking I wonder if… You setup a site with it’s own port you could theoretically access each site like it was it’s own box right? I just blew my own mind in the process. Oh the possibilities.
So I added this to my Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.network "forwarded_port", guest: 85, host: 8085
And then I changed my nginx port to listen on port 85 like so
So now I’m thinking cool let’s fire this up and see if it works so I type
vagrant share --http 85
And that works just fine if you take WordPress out of the situation but that defeats the purpose here since I work with primarily with WordPress. So, what do I do now? We’re getting passed all of the checkpoints on this except for WordPress and the reason is it’s determining the home and site url either by the DB or the wp-config file. What we need to do here is make the install URL agnostic so that it will work with any domain.
We we need to either change tht in the DB or update the config. Updating the config is much easier so let’s just do that.
Bam! we are in business you type up
vagrant share --http 85 and everything runs cool as ice.
But what about images? And other things? Just throw in a proxy pass like in the example below and everything works wonderfully.
Now anyone you share that with will be able to help checkout your local machine without any trouble they can even login and poke around the admin.