Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't view Laravel project in browser with Vagrant

I am trying to get a Vagrant/Laravel setup going, but there is only one problem: when I run php artisan serve on my Vagrant VM, and try to view the project on my host machine browser, the browser says it can't connect/page isn't found.

Here is my Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise32"
  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.network "private_network", ip: "192.168.50.4"
  config.vm.provider :virtualbox do |vb|
    vb.name = "dev_host"
  end
end

After I vagrant up, I cd into my Laravel project folder and run php artisan serve and it runs on localhost:8000, so I go to 192.168.50.4:8000 and it does not show up.

Any comments are appreciated!

like image 808
mkel23 Avatar asked Sep 04 '25 17:09

mkel23


2 Answers

You have to bind the PHP server to the specified IP (192.168.50.4), or to all interfaces (0.0.0.0). Even the port forwarding uses the implicit NAT interface instead of the loopback (localhost, 127.0.0.1) on the VM.

like image 102
tmatilai Avatar answered Sep 07 '25 10:09

tmatilai


I was facing same problem

I made changes in vagrantfile

config.vm.network "private_network", ip: "192.168.33.10"    
config.vm.network "forwarded_port", guest: 8000, host: 8000

and ran following command to start laravel

php artisan serve --port=8000 --host=192.168.33.10

It works for me

Happy coding

like image 30
Manish Nakar Avatar answered Sep 07 '25 10:09

Manish Nakar