iplayjumanji2
iplayjumanji2

Reputation: 47

add multiple sites to laravel homestead, but first site appears for both domains

I have homestead set up and I had my first project working fine, but when I added my second project the url just mimics the first project.

Below is my mapping:

folders:
    - map: ~/username/project1
      to: /home/vagrant/project1folder

    - map: ~/username/project2
      to: /home/vagrant/project2folder/

sites:
    - map: homestead.app
      to: /home/vagrant/project1folder/public

    - map: orb.app
      to: /home/vagrant/project2folder/public

and my hosts file

  192.168.10.10   pj1.app www.pj1.app
  192.168.10.10   pj2.app www.pj2.app

Upvotes: 2

Views: 1252

Answers (1)

Pistachio
Pistachio

Reputation: 1652

There are a few reasons this could happen.

Firstly, I see your host file points to the wrong URL's. Do this in your hosts file

192.168.10.10   homestead.app
192.168.10.10   orb.app

You haven't defined pj1.app or pj2.app anywhere in your homestead.yaml file.

Secondly - if your hosts file actually is correct and you put the wrong thing in your question - homestead.yaml file is very picky when it comes to whitespaces. I've noticed plenty of times it won't work after adding a new site, because my editor was for some reason messing with the whitespaces so vagrant failed.

Try this:

sites:
    - map: homestead.app
      to: /home/vagrant/project1folder/public
    - map: orb.app
      to: /home/vagrant/project2folder/public

Notice no break betweent he two lines.

Of course, do vagrant provision after making changes to make sure homestead serves the new sites (from your homestead folder)

Also, you don't have to define a folder for every project.

My personal homestead.yaml file has this:

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

sites:
    - map: site1.dev
      to: /home/vagrant/Projects/site3/public
    - map: site2.dev
      to: /home/vagrant/Projects/site2/public
    - map: site3.dev
      to: /home/vagrant/Projects/site3/public

This would, on my windows machine, map the Projects folder to C:\Users\MyUsername\Projects as ~ basically means your user folder

As you can see, I define one Projects folder and multiple sites go under those folders. It will make everything much simpler for you, especially when adding new projects.

Upvotes: 3

Related Questions