Allowing for other machines on network to point to host machine that's using Trellis

I finally got Trellis up and running (yay!) but I’m wondering how to have it set up so other machines on my local network can point to the site(s) on my machine. I’m assuming it has to do with vagrant-hostmanager but not sure how to tweak it. Thanks in advance for the help!

1 Like

vagrant-hostmanager sets the ip address in the Vagrantfile to the domain you set for the development environment in Trellis:

# /etc/hosts
## vagrant-hostmanager-start id: 50e5239c-f89a-4c34-871d-ab0889380f87
192.168.50.5     example.dev
192.168.50.5	www.example.dev
## vagrant-hostmanager-end

so you don’t have to do it manually.

There’s probably a few different ways you could expose your site on your machine.

For me, the simplest, which I’ve used for a client demonstration with a laptop connected to a screen with a laptop in front of me and an iPad in the clients hands so that they can also control it was to use BrowserSync in Sage.

On my development machine I did the following:

# assuming you've already installed bower and npm
cd ~/sites/example.com/site/web/app/themes/sage
gulp watch

which watches for changes and starts BrowserSync which in turn temporarily serves the site across the network:

[16:59:46] Using gulpfile ~/sites/example.com/site/web/app/themes/sage/gulpfile.js
[16:59:46] Starting 'watch'...
[16:59:46] Finished 'watch' after 39 ms
[BS] Proxying: http://example.dev
[BS] Access URLs:
 ------------------------------------
       Local: http://localhost:3000
    External: http://192.168.0.3:3000 # this is the one you give to others
 ------------------------------------
          UI: http://localhost:3001
 UI External: http://192.168.0.3:3001
 ------------------------------------
[BS] Watching files...

giving you an IP address to point other machines on your network to also connect to the site.

For showing a client, it means they can see the responsiveness in action as well as give you a chance to see where they look at and how they interact with it.

I haven’t tried leaving a site up on a permanent basis though, since I’d halt Vagrant machines as I switched projects.

Couldn’t the other machines on the network install Trellis and use the same code? Or are you building a staging environment for people to work on?

1 Like

Congrats :smile: it’s tricky to begin with but worth the time put in learning it

Thanks for the help and suggestions Paul! Much appreciated. I’m not using Sage since we use Foundation instead of Bootstrap but I do use Gulp and BrowserSync so I’ll have to give that a shot. Seems like there should be a way to route the domain from another machine on the network to my machine’s local network IP and then have that resolve to the VM’s IP though shouldn’t there? When I used MAMP previously I used it along with VirtualHostX but that works with MAMP and writes something like this to etc/hosts:

# VHX START
127.0.0.1  example.com
fe80::1%lo0 example.com
# VHX STOP

FYI @Brian_Larson - if you’re interested in trying Sage w/ Foundation: https://github.com/schikulski/sage-foundation

You should be able to play with the Apache vhosts or hosts.conf to get the non-proxied URL accessible from other local machines…I just can’t recall how to do so at the moment :sweat: but the proxied URL as noted by @paul_tibbetts should work on any machine connected to the same network.

Thanks on multiple accounts @runofthemill! I’ll look into this and report back if I have any questions or hopefully, luck. Still new to most server config business. I also ran across Vagrant Share but running that command triggered the error below. As for using the BrowserSync proxied URL I’m assuming I would want to be using relative URLs throughout correct? Roots’ Soil plugin should do the trick you think?

Brian-Larsons-iMac:trellis brianlarson$ vagrant share
==> default: Detecting network information for machine...
    default: Local machine address: 192.168.50.5
Vagrant was unable to detect an HTTP port for your machine.

Your Vagrant machine is reporting that it is accessible at
the address: '192.168.50.5'.

Vagrant tries some common HTTP ports to try to find a listening
HTTP server, but all the attempts failed. There are a few options
to fix this error:

  1. Turn off HTTP sharing with the `--disable-http` flag.

  2. Have your HTTP server listen on port 80, 3000, 4567, 8000,
     or 8080. Vagrant will automatically try these.

  3. Specify an HTTP port explicitly to vagrant share with the
     `--http` flag.

  4. Make sure that the address above along with your HTTP port
     are accessible from this machine. Sometimes firewalls or
     binding to the wrong IP cause it to become inaccessible.
1 Like

Are you running Apache/nginx on your computer, separately from Vagrant? Did you check option #4, Make sure that the address above along with your HTTP port are accessible from this machine.?

All the URLs should be relative when proxied through BrowserSync - unless they weren’t relative in the first place. Soil should help take care of URLs the WordPress itself generates, but I’m not sure it’ll do anything for absolute URLs that are in the DB or code you introduced.

Ok so duh. I switched the ports that MAMP was using (trying to move away from MAMP for good here) and that seemed to make a difference. It seems to me though like I should be shifting away from vagrant share and moving to Nginx Server Blocks (Nginx’s version of Apache vhosts). That sound right?

Well, I’ve never used vagrant share but Apache vhosts works for me. So hopefully nginx server blocks would too?? :yum:

I run Apache in my OSX dev setup with a setup similar to (i.e. partially based off) the one here which uses Xip.io:

It also allows you to use the service xip.io to use the URL http://client1.[LOCAL IP].xip.io to access your sites from another machine (or device) on your local network. So, if your machine’s local IP address (not your public IP address), is 192.168.1.10, the URL for a site might be http://client1.192.168.1.10.xip.io. […]

Xip.io is offered for free by Basecamp and provides one of the simplest services on the internet. They run a simple DNS server that redirects all traffic to *.xip.io back to the IP address indicated by the subdomain.

I haven’t tried it with WordPress, but could be useful for you.

Thanks again @runofthemill. Man, the Nginx Server Blocks stuff is making my head spin and thanks for reminding me about Xip.io. I know VirtualHostX uses (at least the old version). Hopefully I’ve at least narrowed it down to pursuing the server block route for meow though!

1 Like