This post is also available in: Português
Well, this isn’t actually automatic mapping, but I’m pretty sure that if you googled for it, this tutorial is what you’re looking for.
I work on multiple sites at a single day, and I have to navigate, add and delete them all the time. Here’s what the default site on Homestead looks like:
In the example above, every time you need to add a new site, you have to create a folder, manually add it to Homestead.yaml, edit the host and all that stuff.
I wanted something more practical, so I created a single domain that hosts all my websites, and it looked like this:
So, to create a new site, I just create a folder for it, and it’s ready to use. Another advantage is that I can quickly access the development enviroment on Google Chrome, because the auto-complete funcion doesn’t compete with the production website.
Example: Let’s say I have client1.local as my development environment, and client1.com as the production environment. To access the development website, I would have to type the whole domain up until .local for the auto-complete to differentiate between them. With that config, it gets easier to autocomplete.
The downside of it is that you lose granularity over specific PHP versions for specific projects, but if for some reason you want to use PHP 5.6 on some website, you can just create a new mapping for it as you would normally do, the above is just a convenience for generic projects.
Anyway, here’s how to do it, step by step:
- Edit Homestead.yaml and add these configs:
folders: - map: C:\projects to: /home/vagrant/projects sites: - map: e.local to: /home/vagrant/projects #ports: (optional but recommended, so you don't have to type e.local:8000) # - send: 80 # to: 80
- Run vagrant up as you normally would (If you can, destroy or reprovision it first. Be careful though, as you might lose databases)
- SSH into your vagrant by typing vagrant ssh
- Elevate yourself as root with sudo -i
- Type vi /etc/nginx/nginx.conf
- Add autoindex on; here:
# Basic Settings
- Run service nginx restart
- Edit your hosts file on C:/Windows/System32/drivers/etc/hosts and add this line:
- Access http://e.local on your browser, click the project you need and start working with no hassle! 🙂