Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Randy_91's avatar

Getting stancl/tenancy working per domain in homestead

I have set up multi-tenancy per domain/database following the quickstart steps in the stancl/tenancy docs.

https://tenancyforlaravel.com/docs/v3/quickstart

I have got as far as creating the users in the tenant databases using tinker at the last step of the quickstart tutorial but the domains don't work for me. This because I am not quite sure how to set it up in Homestead properly.

I am using Homestead on a windows machine and add the sites to the Homestead.yaml file:

- map: ats.test
      to: /home/vagrant/laravel_projects/ATS/public

I then add them to my hosts files in windows and then provision the vagrant box and it works :

 # localhost name resolution is handled within DNS itself.
127.0.0.1               localhost
#	::1             localhost

192.168.10.10        	laravel-admin.test
192.168.10.10           ats.test
127.0.0.1               phpmyadmin.test

But if my central domain is ats.test and I add two tenants with domains :

foo.localhost bar.localhost

How do I get these working on homestead?

0 likes
13 replies
deansatch's avatar

You just add them to your hosts file too on the same ip


192.168.10.10           ats.test
192.168.10.10           foo.localhost
192.168.10.10           bar.localhost

Randy_91's avatar

I have tried that, it doesn't seem to work. I don't have also add them to the Homestead.yaml do I?

deansatch's avatar

No, just the hosts file. Did you check that the databases have been created for the tenants and the domains are definitely correct?

Randy_91's avatar

Yes, they are exactly as is in the quickstart steps.

deansatch's avatar

ah sorry, yes you do need to add them to your yaml file.

        map: ats.test
        to: /home/vagrant/code/public
        map: foo.localhost
        to: /home/vagrant/code/public
        map: bar.localhost
        to: /home/vagrant/code/public

Randy_91's avatar

still get: This site can’t be reached foo.localhost refused to connect.

deansatch's avatar

Did you reload homestead server to pick up the changes?

vagrant reload --provision

deansatch's avatar

so, domains are set up in hosts file, and yaml file, and your central database 'domains' table shows both of those domains, and both tenant tables exist and have migrated? If so and it still isn't working you might need to check your log files to find the cause

One thing to consider...I'm not so sure you can use localhost as a domain extension - I would try something like foo.test and bar.test as your tenant domains - I get the same error as you if I try and visit foo.localhost but foo.anythingelse gives a completely different error

Randy_91's avatar

yes that pretty much sums it up:

# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
127.0.0.1               localhost
#	::1             localhost
192.168.10.10           blog.test
192.168.10.10        	adminlte.test
192.168.10.10        	laravel-admin.test
192.168.10.10           ats.test
192.168.10.10           coralsconnect.test
192.168.10.10           larabid.test
127.0.0.1               phpmyadmin.test
192.168.10.10           peoplebank.test
192.168.10.10           foo.localhost
192.168.10.10           bar.localhost

yaml

sites:
    - map: blog.test
      to: /home/vagrant/laravel_projects/blog/public
    - map: phpmyadmin.test
      to: /home/vagrant/laravel_projects/phpmyadmin
    - map: adminlte.test
      to: /home/vagrant/laravel_projects/adminlte/public
    - map: adminlte.test
      to: /home/vagrant/laravel_projects/laravel-admin/public
    - map: ats.test
      to: /home/vagrant/laravel_projects/ATS/public
    - map: coralsconnect.test
      to: /home/vagrant/laravel_projects/coralsconnect/wordpress
    - map: larabid.test
      to: /home/vagrant/laravel_projects/larabid/public
    - map: foo.localhost
      to: /home/vagrant/laravel_projects/peoplebank/public
    - map: bar.localhost
      to: /home/vagrant/laravel_projects/peoplebank/public

databases:
    - homestead

features:
    - mariadb: false
    - ohmyzsh: false
    - webdriver: false

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp

deansatch's avatar

could you try a tenant with a .test extension? I think its just the .localhost that is causing the issue

Lounesios's avatar

I have the same problem, I followed the Quick Start in the documentation and all the steps of what you said but it does not work for me, any idea? i am using laravel 7

Please or to participate in this conversation.