How configure Homestead and xip.io?
Asked Answered
T

2

3

I want to access from other devices (iphone, android device, etc) to my sites on homestead in my machine. My machine and all device are on same network.

I want to use http://xip.io but I could not confgure it.

My ip machine is 192.168.0.12

The ip for sites on Homestead is 192.168.10.10

This is the file hosts:

127.0.0.1   localhost
127.0.1.1   host

#Virtual Hosts on Homestead
192.168.10.10   siteOne.com
192.168.10.10   siteTwo.app
192.168.10.10   otherSite.app

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

and this is Homestead.yaml

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Homestead-Projects
      to: /home/vagrant/Homestead-Projects

sites:
    - map: siteOne.com
      to: /home/vagrant/Homestead-Projects/SiteOne/public
    - map: siteTwo.app
      to: /home/vagrant/Homestead-Projects/SiteTwo/public
    - map: otherSite.app
      to: /home/vagrant/Homestead-Projects/OtherSite/public

databases:
    - homestead
    - db_siteOne
    - db_siteTwo
    - db_otherSite

variables:
    - key: APP_ENV
      value: local

# blackfire:
#     - id: foo
#       token: bar
#       client-id: foo
#       client-token: bar

# ports:
#     - send: 93000
#       to: 9300
#     - send: 7777
#       to: 777
#       protocol: udp

how can I do it?

Thanks!

Trussell answered 14/3, 2016 at 15:30 Comment(0)
E
3

You can access your site by browsing to http://<your_local_ip>.xip.io:8000.

To understand how it works you need to know two facts:

  • Domain example.your_ip.xip.io resolves to your_ip.
  • By default local port 8000 is mapped to port 80 of your homestead virtual machine.

Please note, xip.io acts as a "DNS" and you don't need to edit your hosts file to access your homestead site from other devices on local network.

This solution works perfectly if you have only one site mapped in homestead. If there are multiple sites, only last mapped site gets served. A workaround is to use site identifier in your url. http://<your_site>.<your_local_ip>.xip.io:8000 still resolves to same endpoint but now you can update your homestead nginx to pickup the site identifier and serve the right site.

Eliason answered 2/8, 2016 at 7:21 Comment(1)
Thanks for these hints. I'll update my answer in another question: https://mcmap.net/q/86830/-how-do-you-access-a-website-running-on-localhost-from-iphone-browserMusjid
C
1

I believe Homestead already ships with it by default,

in my case i just added an entry on the hosts files, /etc/hosts (i'm on a mac machine), like this:

127.0.0.1 http://app.ip.address.xip.io:8000

(usually the default port is 8000), and then add an entry on the homestead yml config file (you can reach by typing homestead edit on your console.

enter image description here

and that should do it.

Cranny answered 1/4, 2016 at 15:35 Comment(2)
I couldn't get your example working. And laravel.com/docs/5.5/homestead#installation-and-setup recommends 192.168.10.10 homestead.test in the hosts file, which looks quite different from what you're suggesting. I've been able to get 192.168.10.10 mysite.app.192.168.1.130.xip.io to work but only in the browser on the same computer where Homestead is installed. Browsing to that URL from iOS doesn't work.Musjid
I updated my answer. in short to access mysite.app from other devices you only need to add a new mapping to your Homestead.yaml file for mysite.app.192.168.1.130.xip.io domain to point to same directory as mysite.app then run provision and browse to http://mysite.app.192.168.1.130.xip.io:8000 from other devices on same network. Please let me know if this needs clarification. - map: mysite.appEliason

© 2022 - 2024 — McMap. All rights reserved.