If you’ve ever tried to start up multiple Virtual Machines using Laravel Homestead, you may have encountered the following error:

Basically, Vagrant is complaining that you’ve told it to try to forward a port on the guest (VM) machine to a port that is already in use on your host machine. It’s unable to do that, so it spits out this error and stops. But you haven’t told it to do any port forwarding; you may not even want any ports forwarding! So what’s going on?

This is due to Homestead having a default set of port mappings which automatically forwards the ports of typical services a web developer would use, to the host machine (such as the web server and MySQL database). This is usually very convenient and follows Laravel’s style of providing you with a default sane configuration which lets you get something up and running as quickly as possible.


Changing the port mappings

If you wish to change the port mappings that are in conflict you can do this via the Homestead.yaml file. In fairness to the Laravel team, they do provide instructions on these port mappings and how to forward additional ports if you need too here. However they don’t really tell you that you can use the same syntax to override these default ports too. So all you have to do is open up that file and add the overrides.

Keep the to port above 1024 (below that they are restricted) and you’re good to go. You can also use guest and host in replace of send and to respectively if you wish.


Disable default port mapping

Alternatively, you may prefer to disable the default port mappings completely. I don’t use the forwarded ports as I prefer to create .test domains instead that point to my VM. In fact this is what I wanted to do prior to deciding to document it in this blog post. I have a variety of programs and VM’s online at any given time, normally they don’t collide (albeit out of pure luck) but this time they did and it annoyed me enough to look into it.

The answer isn’t documented (that I can see at the time of writing this) but if you take a quick look inside the homestead.rb file of the homestead source code, you’ll find this line:

Notice the false check on default_ports? So all you have to do, is add this to your homestead.yaml file, and you’re good to go!