Laravel 5 Homestead Multiple Sites on Local Network - laravel-5

I have two Laravel projects on a Homestead machine.
Homestead.yaml
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
- map: blog.app
to: /home/vagrant/Code/Blog/public
and /etc/hosts:
192.168.10.10 homestead.app
192.168.10.10 blog.app
And everything works as expected. But when I want to access sites from a phone on a local network and go to
192.168.1.100:8000
It takes me to a Blog project. Is there a way for all projects to be accessible at all times?
I read this How to connect to Homestead which has multiple sites through mobile device?, but you have to pick one project to be accessible. And you have to edit Homestead.yaml and reload vagrant every time you want to swap projects.

I have just figured this out myself, and I have posted answers here (Homestead cant access second site remotely) and here (Laravel homestead multiple sites choose which one is locally accesable).
In short:
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
port: 81
- map: blog.app
to: /home/vagrant/Code/Blog/public
ports:
- send: 8100
to: 81
Then access your homestead.app project via http://192.168.1.100:8100.

Related

Accesing Homestead Vagrant from LAN via URL

I'm trying to set up the hosts file in my laptop to allow connecting to my Vagrant box on my PC via URL, instead of just IP.
The IP part worked by itself just fine, I had to enter the IP of my PC, for example: 192.168.1.15:8000 and I got connected to the default website. Now here's my first question actually, why do I get connected to one particular website, even though I have two.
My homestead.yaml file looks as such:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ssh_key.pub
keys:
- ssh_key
folders:
- map: /HomesteadCode
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/public
- map: phpmyadmin.dev
to: /home/vagrant/Code/phpmyadmin
But I get connected to what is homestead.app. How would I then connect to phpmyadmin.dev?
And my other question is, how do I set up the hosts file on my laptop to allow connecting using the URL? I set up the hosts as such:
192.168.1.21 homestead.app
192.168.1.21 phpmyadmin.dev
and it didn't work, even if i entered homestead.app:8000 into the browser.
And the last question, why does it work on ym local PC, even if I set up the hosts file like so:
192.168.10.10 homestead.app
192.168.1.21 homestead.app
192.168.1.21 phpmyadmin.dev
192.168.10.10 phpmyadmin.dev
Even if there are two entries for homestead, one seemingly wrong, it still works.

Homestead cant access second site remotely

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?
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:
http://rentmanager.test.192.168.5.124.xip.io:8000
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':
# Vagrant Sites External Access
192.168.10.10 sitescanner.test.192.168.5.124.xip.io
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:
- map: sitescanner.test
to: /home/vagrant/Code/sitescanner/public
- map: sitescanner.test.192.168.5.124.xip.io
to: /home/vagrant/Code/sitescanner/public
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
http://sitescanner.test.192.168.5.124.xip.io:8000
Anywhere on your network! Hope this helps.
While I'm thinking about it, there is a final consideration for this configuration:
You may want to set a static IP address on your host machine if possible. If you're being assigned a dynamic IP address via DHCP it's possible (and likely) for this configuration to eventually break if you're ever assigned a new IP.
According to the documentation found at https://laravel.com/docs/5.4/homestead
you don't need to specify ports when adding multiple sites
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
- map: another.app
to: /home/vagrant/Code/another/public
then add the following to your hosts file
192.168.10.10 homestead.app
192.168.10.10 another.app
make sure to run vagrant reload --provision
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.
Instead of using port: 8100 in your sites configuration, you should have used port: 81.
Instead of guest and host, use send and to.
I used the exact same setup as you except for those two differences, and it works for me.
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: 81
ports:
- send: 8100
to: 81
You would then be able to access your app via http://app2.app:8100 if your hosts file has an entry for app2.app or via http://192.168.0.5:8100 if you aren't using the hosts file.

PhpMyAdmin on Laravel 5 Homestead, Windows

I downloaded phpmyadmin to my /Code folder, and then updated my Homestead.yaml file:
folders:
- map: C:\Users\{ myname }\Code
to: /home/vagrant/Code
- map: C:\Users\{ myname }\Code\phpmyadmin
to: /home/vagrant/Code/phpmyadmin
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
- map: phpmyadmin.app
to: /home/vagrant/Code/phpmyadmin
I updated my hosts file also...
{ ip from homestead.yaml} phpmyadmin.app
When I browse to phpmyadmin.app it displays the same site as homestead.app.
I'm using Windows.
Is there some way to restart homestead? How do I get this to work?
You'll need to reprovision your homestead vm with
vagrant provision
See Adding Additional Sites

No laravel sync folders in homestead vagrant on windows

i installed vagrant lately on my windows 7 machine, i successfully runned the virtual machine because i can ssh to it but no synchronization between my local project and the homestead.
my yaml file is like :
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /Users/User/Homestead/projects
to: /home/vagrant/sites
sites:
- map: laravel.dev
to: /home/vagrant/sites/laravel/public
hhvm: true
databases:
- homestead
variables:
- key: APP_ENV
value: local
My laravel project is inside projects folder in my local homestead directory, but it seems that the sites folder that links to it is not synced with it !!
i'm not good at unix command line but is it weird that ls -la command work but ls alone don't seem to work as i saw if tutorials ?
update :
After changing the hosts file setup for : 127.0.0.1 laravel.dev to 192.168.10.10 laravel.dev the site was accessible in my browser, but the problem of no syncronization still happening (i had to install a new laravel in vangrant) i want to deplay my project from wamp to projects folder and be syncronized with "sites" in homestead
Edit your Homestead.yaml
In the line
---
folders:
- map: E:/projects //your projects folder here
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
Now if you are using Windows, open notepad as administrator and your hosts
System32/drivers/etc/hosts
192.168.10.10 laravel5angularapp.dev
192.168.10.10 angular2laravel.dev
192.168.10.10 laravel5-angular2.dev
192.168.10.10 yourproject.dev
Now access your homestead
homestead up
homestead ssh
Inside homestead
cd Code
ls -a
All your projects should appear here, then
cd ~
then
serve yourproject.dev /home/vagrant/Code/yourlaravelprojectname/public/
Then
sudo service nginx restart
Or
homestead reload
Your project should be running in
http://yourproject.dev
I've tried many things but none of them worked. Finally i've changed map folder to the full path version and then run the vagrant reload command and it was ok.
Homestead.yaml
folders:
- map: C:/Users/username/Code
to: /home/vagrant/Code.
vagrant reload
You can use ~/Homestead/projects in windows is the same the C:\Users\your_user\your_folders

Homestead 2.0 multiple sites, all link to the same url

Hee guys, little question: So i have setup the Homestead 2.0 and everything is working fine. I wanted to add another project in the same code directory but link it to another url. So i added it in the sites list but when i visited laravel.app it all works fine, but when I visit larabook.app it shows me the laravel.app page! Both urls are linked to 192.168.10.10 in my /etc/hosts file.
I have tried restarting my mac and restarting the vm but nothing is working :'(
/etc/hosts
192.168.10.10 laravel.app
192.168.10.10 larabook.app
Homestead.yaml
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: laravel.app
to: /home/vagrant/Code/Laravel/public
- map: larabook.app
to: /home/vagrant/Code/Larabook/public
databases:
- homestead
- larabook
Assuming your Homestead.yaml file above
type in:
$ vagrant global-status
will display something like;
id name provider state directory
--------------------------------------------
77c5c30 default virtualbox running et....
type in:
$ vagrant provision 77c5c30
Of course this assumes you only have 1 VM, if you have others then read the instruction when you run vagrant provision
This works for me, and didn't lose the database:
$ homestead halt
$ homestead up --provision
Try this
folders:
- map: ~/Code/Laravel
to: /home/vagrant/Code/Laravel
- map: ~/Code/Larabook
to: /home/vagrant/Code/Larabook
sites:
- map: laravel.app
to: /home/vagrant/Code/Laravel/public
- map: larabook.app
to: /home/vagrant/Code/Larabook/public
databases:
- homestead
- larabook
Note: look at the changes i have made to the folders section.
find out more from https://www.easylaravelbook.com/blog/configuring-multiple-laravel-homestead-sites-and-databases/#top
after run
$ homestead halt
$ homestead up --provision

Resources