Vagrant - Homestead Setup Multiple sites - laravel

I have mapped the folders etc using the homestead.yaml;
ip: "192.168.10.10"
...
folders:
- map: /Users/User/Desktop/folder/Homestead/First
to: /home/vagrant/First
- map: /Users/User/Desktop/folder/Homestead/Second
to: /home/vagrant/Second
sites:
- map: first.dev
to: /home/vagrant/First/public
- map: second.dev
to: /home/vagrant/Second/public
But when i set up the hosts file, etc/hosts with my second.dev to 192.168.10.10 i find that the mapping goes to first.dev, not the mapping that i have set up for second.dev.
How can i go about making the mapping return the correct site?
EDIT: I am using Mac OS X.

Using Vagrant commands
Run the command vagrant provision within terminal or your command prompt within the folder where homestead files are located.
Another equivalent command is vagrant up --provision this will provision the vagrant machine as well as run it.
Using Global Homestead
You can use the command homestead provision to re-provision the vagrant machine, regardless of the place you call it from within the terminal.
Alternatively, you can use the serve command to add the information to your Homestead.yaml file for you. Like so;
serve domain.app /home/vagrant/Code/path/to/public/directory
But add this to your hosts file so you can access the your app via domain.app in your browser.

Related

App on a Vagrant box running Laravel Homestead only displays 'It Works' upon fresh install of Laravel App

I install a new Laravel app into my /sites folder called 'blog' using the laravel new blog terminal command.
The site builds fine, no errors on the terminal.
Then I used the subl /etc/hosts command to open up the hosts file in Sublime Text 3. Here is the contents of that file.
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 laraveltest.app
127.0.0.1 makoto.app
127.0.0.1 modelawiki.app
127.0.0.1 fresher.app
127.0.0.1 blog.app
Right now let's focus on blog.app.
I then use the subl Homestead.yaml command to open and edit the Homestead.yaml file and update the maps. Here's the contents of that file.
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/www/sites
to: /home/vagrant/sites
sites:
- map: blog.app
to: /home/vagrant/sites/blog/public
- map: laraveltest.app
to: /home/vagrant/sites/laravelTest/public
- map: makoto.app
to: /home/vagrant/sites/Makoto
- map: modelawiki.app
to: /home/vagrant/sites/modelawiki
- map: fresher.app
to: /home/vagrant/sites/fresher/public
databases:
- homestead
I then run the homestead provision command which is an alias for vagrant provision to update everything and get the site up and running.
Now before running the vagrant provision command, every other site (laraveltest.app:8000, makoto.app:8000, etc.) worked just fine, and or displayed the Default Laravel Splash screen (laraveltest.app:8000).
When visiting any of the sites mapped in the homestead.yaml file, all I'm getting is the following page displayed...
http://imgur.com/a/6IIkD
Here's the HTML output.
<html><body><h1>It works!</h1></body></html>
I'm confused on what I did wrong. I'm a newer user going through the Laravel Tutorials on LaraCasts. I followed CodeCourses videos on YouTube to help me install the Vagrant Box onto my machine.
I've also tried to see what was out there on the net for this issue and all i could find is this article on laravel valet... but it seems as though this isn't the tutorial I need.
https://laracasts.com/discuss/channels/laravel/valet-v112-update-just-keep-getting-the-it-works
Edit: I'm currently in the process of uninstalling the vagrant box running laravel/homestead. I did the vagrant destroy <id> command and the vargrant box remove. I then edited the /etc/hosts file and removed all the edited custom app names. I then also deleted my Homestead folder containing my homestead.yaml file. I'm hopefully starting with a fresh install here soon.
(Posted answer on behalf of the OP).
I reinstalled everything including the Vagrant box, and Homestead. Everything runs as normal. Don't know what happened. However the only way I can connect to my sites are to actually type the port in the URL. i.e. blog.app:8000. If i visit blog.app by itself, then the "It Works!" header comes back up and the laravel site goes away.
I'm thinking this might be an issue with nginx, and port forwarding? Since this is the case and the original question has been answered by myself, I'll be asking a new question about port forwarding and Laravel homestead.
Have you configured your sites-available ? try this line inside the virtual machine (after command vagrant ssh):
serve blog.app ~/sites/blog/public
It seems that you have already solved the problem, as you made an edit to your original question and linked to a new question. However, one thing I noticed that may have been causing your problem is the IP in your /etc/hosts file is does not match the IP in your Homestead.yaml file. When I use Laravel Homestead, I make sure that my /etc/hosts and Homestead.yaml files have identical IPs. I always get the Laravel splash page when I do this. Hopefully this is useful for future Vagrant boxes.

Laravel Homestead No input file specified

at the moment I am having a real nightmare trying to get Laravel Homestead to work. Usually when I have had this issue on my work machine I simply run vagrant provision however on my personal machine when I run vagrant provision nothing really happens it just hangs for a few seconds and then it is ready for another command.
Here is my setup Homestead.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: helloworld.app
to: /home/vagrant/Projects/HelloWorld/public
databases:
- homestead
My host file:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
192.168.10.10 helloworld.app
When I run vagrant up I get no errors either. I just get No input file specified. when I visit the URL in my browser.
Has anybody had this issue before?
Thanks, Nick
Looks like there is a line break after the sites: parameter. If thats true, get rid of that and run vagrant provision again.
Make your app/storage writeable by your homestead user.
I do not know if this is the case or not but if you are starting / stoping VM via the GUI, it may behave differently. Using vagrant <command> is always better for things like halt etc.
Update:
Make sure nginx config in your VM mirrors what you have on your yaml config file for homestead. I mean the public is also pointed in the nginx configs so check files under etc/ngnx/sites-available/ and make sure root points to where it is supposed to.
Update app/storage permissions with chmod -R 777 app/storage
Try running homestead up --provision it is homestead provision not vagrant.
You can find more information here some of the tutorial vids might require a subscription but I know some stuff is free there. Just in case it might help.

Laravel Homestead (Windows)

Today I have been trying to install the Laravel library together with Laravel Homestead.. But I can't seem to get it working.
The first thing, Laravel documentation tells you to do: composer global require "laravel/homestead=~2.0", but it didn't work.
So I searched the internet some and found: composer global require "laravel/homestead=~3.0", which actually worked.
But now when I try to run the homestead command in my command line, it gives me this: http://prntscr.com/9perhj, that's the only thing it's giving me.
I have added the directory to my path variable.
I hope someone can help me.
Thanks in advance!
Homestead itself command will return this expected screen. You would need to pass the command you want to run.
At first, run homestead init so that it will create the Homestead.yaml configuration file
This is an old question but I thought I'd put up my answer since it took me multiple tries to get it right and I documented the process while I was doing it so I wouldn't have such a hard time in the future.
Note: You should NOT have NginX, PHP, MySQL, etc. installed on your machine. The Vagrant Homestead virtual box provides all of this functionality. I had some issues where I had NginX and MySQL on my machine and it was connecting to my local machine's MySQL when it should be connecting to the virtual box's MySQL.
Without further ado, this is how I set it up for my Windows 7 machine:
Prerequisites:
VirtualBox:
https://www.virtualbox.org/wiki/Downloads
Vagrant:
https://www.vagrantup.com/downloads.html
Git Bash: A terminal that feels like a Linux terminal. You can do everything you do on an Ubuntu server in Windows.
https://git-scm.com/downloads
Putty: Telnet client that I used for connecting to my VirtualBox Homestead server
http://www.putty.org/
create project folder
open terminal in project folder (something like E:\Projects\Vagrant)
type 'vagrant box add laravel/homestead'
type 'git clone https://github.com/laravel/homestead.git Homestead'
This installs Homestead in the designated project folder.
type 'cd Homestead'
type 'bash init.sh' OR 'init.bat'
This creates a folder in:
C:\Users\USERNAME\.homestead
which has the file:
Homestead.yaml
If you open the Homestead.yaml file it should look something like this:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
databases:
- homestead
The '~/' folder is the equivalent of:
C:\Users\USERNAME\
Change:
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
To:
folders:
- map: E:/Projects/Vagrant/Homestead
to: /home/vagrant/Homestead
sites:
- map: WEBSITE.dev
to: /home/vagrant/Homestead/Laravel/public
goto C:\Windows\System32\drivers\etc
open the file 'hosts' in a text editor
add '192.168.10.10 WEBSITE.dev' (the IP address should match the IP address in the Homestead.yaml file)
open a terminal in E:/Projects/Vagrant/Homestead folder
type 'ssh-keygen -t rsa -C "USERNAME#gmail.com"'
This creates the folder C:\Users\USERNAME.ssh and sets up your SSH Key
type 'vagrant init laravel/homestead'
type 'vagrant up'
You should see Homestead running in VirtualBox
You can use 'vagrant destroy' to kill it when done
Use putty.exe to log in to Homestead
IP Address: 127.0.0.1
Port: 2222
login as: vagrant
password: vagrant
Everything is now ready

How to setup Laravel Homestead server to run locally without being on a network/internet?

Previously, I manually setup my own VM on VirtualBox and configured it so it would also work when I'm coding offline (no internet/not connected to a router). I did this using settings in the VirtualBox GUI and also in Apache on the VM.
Now I'm interested in learning nginx and I've decided to try and use Laravel's Homestead. The tutorials I'm looking at seem to have the assumption I will be accessing the Homestead VM across the network (even though of course it's on the same PC). What do I need to do to ensure the VM will be accessible when I'm offline (like when I'm coding on a plane or train)? I'd like to still be able to have access to the internet from the VM whenever I do get back on WiFi (ie. for apt-get, etc.).
(note: My host machine is running Windows 7 64-bit)
Download and install fresh copies of Vagrant and Virtualbox.
https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2.msi
http://dlc-cdn.sun.com/virtualbox/4.3.22/VirtualBox-4.3.22-98236-Win.exe
Also download laravel/homestead manually
https://vagrantcloud.com/laravel/boxes/homestead/versions/0.2.2/providers/virtualbox.box
to my downloads folder C:\Downloads\homestead-0-2-2.box
After Installing Virtualbox and Vagrant. Installed laravel/homestead by running the following command in git bash (you can download git bash here: http://git-scm.com/downloads).
vagrant box add laravel/homestead /c/downloads/homestead-0-2-2.box
Run this command inside C:\users\yourusername
git clone https://github.com/laravel/homestead.git Homestead
NB: This will create this folder: C:\Users\yourusername\Homestead
With some files.
Still in Git bash, cd into C:\Users\yourusername\Homestead and run this command:
bash init.sh
NB: this will create a folder C:\Users\yourusername\.homestead that contains Homestead.yaml and some other files
Then Generate an SSH key which you will need when you want to login to your VM by running this command:
ssh-keygen -t rsa -C "youremailaddress#youremail.com"
NB: This will ask some question simply hit enter or type yes and hit enter.
This will create your ssh key inside C:\Users\yourusername\.ssh
Then you need to configure homestead by editing for Nginx
C:\Users\digitlimit\Homestead\Homestead.yaml
You can right-click Homestead.yaml file then click open then choose to open with wordpad.
My Homestead.yaml looks this after editing:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /wamp/www
to: /home/vagrant/Code
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
# blackfire:
# - id: foo
# token: bar
NB: To understand the mapping which is a process of sharing a folder between the host and the VM:
My laravel project is located at C:\wamp\www\laravel
This directory /home/vagrant/Code will be inside the VM after installation.
So what am telling VM is, whenever you see /home/vagrant/Code reference this folder C:\wamp\www\laravel
Also in this:
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
What we are saying here is when i go to my browser and type http://laravel.dev display the content of /home/vagrant/Code/laravel/public which is actually pointing to C:\www\wamp\laravel\public
After editing Homestead.yaml file save your chnages
NB: Before we can use http://laravel.dev in the host web browser to view our laravel project, we need to add this the following to the hosts file located in
C:\Windows\System32\drivers\etc\hosts
Add this ip address under the list of other ip address listed if any:
192.168.10.10 laravel.dev
Finally, go back to your Git bash, ensure you are in
/c/Users/yourusername/homestead and type:
vagrant up
Wait for vagrant to complete its processes. Click yes when you see any dialog box asking for permission to create network adapter on your system
Any VM running on your development machine will be accessible when you're offline. Just make sure you setup your development machine's host file to have the VM's location set.
If you're following the Laravel Homestead Setup:
In scripts/homestead.rb, you'll have a line that has the IP Address of the VM.
# in scripts/homestead.rb
# Configure A Private Network IP
config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
Add this IP address into to your hosts file. This is located usually in C:\Windows\System32\drivers\etc\hosts
#in hosts file
192.168.10.10 yourwebsite.dev

How can I refresh homestead for a new site in my environment?

I'm running Laravel 4 on my development machine (Mac) with homestead and enjoying it thus far but having trouble when adding a new site. The problem is that I add lines like this for a new site in my ~/.homestead/Homestead.yaml file:
folders:
- map: ~/Sites
to: /home/vagrant/Sites
sites:
- map: listingnaples.dev
to: /home/vagrant/Sites/listingnaples.com/public
- map: videocraftersusa.dev
to: /home/vagrant/Sites/videocraftersusa.com/
Then, my /etc/hosts looks like this:
# MY SITES
192.168.10.10 listingnaples.dev
192.168.10.10 videocraftersusa.dev
192.168.10.10 laneyandchris.dev
If i go in and do a homestead destroy followed by homestead up I can access any of those new sites. That deletes my databases though and really sets me back. How do I "refresh" so to speak? If I add myawesomesite.dev to my /etc/hosts, how can I have homestead pick it up?
I tried homestead --provision but that isn't a recognized command.
For what it's worth, in my ~/.homestead/ directory, I do not have a VagrantFile. Not sure where that's at so I can't run a vagrant provision either.
You can also reload the box and the settings
vagrant reload --provision
This reload the box and see if there are changes, if that's the case it will make the changes while reloading
I just ssh using homestead ssh and then add this line
serve domain.app /home/vagrant/Code/path/to/public/directory
where you replace domain.app to your app name, the same you use on your yaml file and your path to your new public site directory, then just homestead up and you could see it active.
Try run vagrant global-status. You'll see the list of running boxes at this time, like this:
MacBook-Pro-lancedikson:~ lancedikson$ vagrant global-status
id name provider state directory
------------------------------------------------------------------------------------------
9710b02 default virtualbox running /Users/lancedikson/.composer/vendor/laravel/homestead
The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"
That's all. Now run vagrant provision 9710b02 and it will be provisioned.
As of Laravel 5 and more importantly Homestead 2.0, just run:
homestead up
Then:
homestead provision
You have to use vagrant provision anyway from the same directory where Homestead.yaml is.
You can run:
homestead up --provision
In my case I had a Homestead.yaml in ~/.homestead/ and in ~/Homestead/.
I am not sure if the default location changed or that I changed it manually (maybe because I did not like the hidden dir), but make sure you don't have multiple Homestead.yaml files. I now symlinked them so I can not confuse myself any further.
But normally, homestead provision or homestead up --provision (when it was turned off) should do.

Resources