Laravel Homestead

Automatically map sites on Laravel Homestead

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:

  • client1.local
  • client2.local
  • client3.local

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:

  • e.local/client1
  • e.local/client2
  • e.local/client3

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 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:

  1. Edit Homestead.yaml and add these configs:
     - map: C:\projects
     to: /home/vagrant/projects
     - 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
  2. Run vagrant up as you normally would (If you can, destroy or reprovision it first. Be careful though, as you might lose databases)
  3. SSH into your vagrant by typing vagrant ssh
  4. Elevate yourself as root with sudo -i
  5. Type vi /etc/nginx/nginx.conf
  6. Add autoindex on; here:
    http {
    # Basic Settings
    autoindex on;
  7. Run service nginx restart
  8. Edit your hosts file on C:/Windows/System32/drivers/etc/hosts and add this line: e.local
  9. Access http://e.local on your browser, click the project you need and start working with no hassle! 🙂

Homestead multiple sites

Tag: , ,