I have one site setup fine, but the second can't be accessed remotely:
My YAML:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Projects
to: /home/vagrant/Projects
sites:
- map: app.app
to: /home/vagrant/sites/app1/public
- map: app2.app
to: /home/vagrant/sites/app2/public
port: 8100
ports:
- host: 81
- guest: 8100
I can access the first site using my IP easily - http://192.168.0.5/
but the second one cannot share the same port, so I've added 81 -> 8100
.
When I try to reprovision my homestead vagrant box it says: There are errors in the configuration of this machine. Please fix the following errors and try again:
vm:
* Forwarded port definitions require a "host" and "guest" value
* Ports to forward must be 1 to 65535
* Ports to forward must be 1 to 65535
Any ideas?
According to the documentation found at https://laravel.com/docs/5.4/homestead
you don't need to specify ports when adding multiple sites
then add the following to your hosts file
make sure to run
vagrant reload --provision
The service xip.io can make short work of this. Here's how:
As an example, I have the following Homesite app setup, 'rentmanager.test'. This is the first application I provisioned on Homestead, so it's the default route. To access this from my local network, all I have to do is go to:
Where 'rentmanager.test.' is the name of my Laravel application on Homestead, '192.166.5.124.' is my IP address on the local network, 'xip.io:8000' is the redirect service domain and the needed port to access the app (8000) outside of the default routing that Homestead sets up.
Now, this works fine out of the box with the first site you provision, but what happens if we have more than one site? That requires a little more legwork. Let's assume we've got a second app called 'sitescanner.test' that we want to access. If I try to access the same URL above with the new app URL, you'll see I'm still served the first application! Let's resolve that as well.
First, you're going to need to add an additional rule to your hosts file. So, assuming our new app is called 'sitescanner.test':
Once that's in place then we have to update the provisioning scripts in Homestead to create the correct virtual host entries so Homestead knows how to route the request. To do that, we'll edit your Homestead.yaml. Under the 'sites:' directive:
Once this is complete, simply 'vagrant halt' (if it's already running), then 'vagrant up --provision' and you should be able to access your site from
Anywhere on your network! Hope this helps.
While I'm thinking about it, there is a final consideration for this configuration:
I do not know which version of Laravel or Homestead you are using, but this is possible. With the Homestead versions documented for Laravel 5.6 or 5.7, you were 95% of the way to having this complete.
port: 8100
in yoursites
configuration, you should have usedport: 81
.guest
andhost
, usesend
andto
.I used the exact same setup as you except for those two differences, and it works for me.
You would then be able to access your app via
http://app2.app:8100
if your hosts file has an entry forapp2.app
or viahttp://192.168.0.5:8100
if you aren't using the hosts file.