Babbu Mann Babbu Mann - 6 months ago 46
PHP Question

Laravel + Homestead + Vagrant not working

I am new to homestead and vagrant, i installed homestead as in laravel documentation but getting timeout error when visit address : 192,168.10.10.

Before this error i was getting error request time out on ip so i uncomment this line :

config.vm.network "private_network", ip: "192.168.10.10"


Then network start working ping.

Also i uncommented this line :

config.vm.network "forwarded_port", guest: 80, host: 8080


So it's started showing me port forward.

Then i made this line uncommented :

config.vm.network "public_network"


But still getting error, don't now what is the error. I checked nginx folder by log in to ssh : vagrant ssh then cd /etc/nginx/sites-enabled

I saw there is no configuration file maybe because vagrant not loading Homestead.yaml file.

Here is my yaml file

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

authorize: ~/.ssh/id_rsa.pub

keys:
- ~/.ssh/id_rsa

folders:
- map: ~/Websites
to: /vagrant/Code

sites:
- map: laravel.dev
to: /home/vagrant/Code/admin/public

databases:
- homestead

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

# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp

Answer

Have you read laravel documentation seriously ? go here and check :

Laravel Documents

After add homestead box your first work is to clone repository :

git clone https://github.com/laravel/homestead.git Homestead

And clone this to in folder where from you want to run your code or websites example :

if ~/Websites then:

cd ~/Websites

Then clone command, after clone cd Homestead run bash init.sh in Terminal it will make a folder in your root directory called .homestead where your Homestead.yaml file will. Edit Homestead file like this:

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

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Websites
      to: /home/vagrant/Websites

sites:
    - map: laravel.dev
      to: /home/vagrant/Websites/admin/public

databases:
    - homestead

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

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp

After edit add your ssh key using this command in terminal :

ssh-keygen -t rsa -C "you@homestead"

Keygen should create files in .ssh folder in document root but if not then create folder .ssh then paste it from document root to ssh folder so you no need to edit Homestead.yaml file

When this done change directory to : cd ~/Websites/Homestead

Now run this :

vagrant up

If any edit in yaml file or Vagrantfile then run this :

vagrant reload --provisions

Maybe that should fix your issue otherwise something wrong with your PC :D

Don't forget to add this in /etc/hosts file :

192.168.10.10      laravel.dev