
Configuring Homestead for Multiple Laravel Projects
This is part 2 of the tutorial series about using Homestead for Laravel development on your computer. The first part explained steps to install Homestead for a Laravel project. In this part 2, you can learn about using Homestead for more than one Laravel installation in a single box.
If you do not have already a second Laravel project, you can create one using one using the below composer commands (unless, of course, you already know how to do it – otherwise simply skip to the next paragraph.) :
If you do not already have a Laravel project, you can create one executing:
laravel new yourprojectname2
or
composer create-project --prefer-dist laravel/laravel yourprojectname2
Then
cd yourprojectname2
Once you arrive in your second project’s directory in the command line, run:
vagrant init laravel/homestead
This command will add the necessary VagrantFile in this new project.
If you previously followed instructions as described in part 1 of this tutorial series to install Homestead directly in your first project’s directory, open the directory of your first original project file and open its Homestead.yaml file in your code editor. Else if you had installed Homestead by cloning it from GitHub and had used bash init.sh to initialize it, the Homestead.yaml file is most probably under your user home directory – i.e. ~/.homestead/Homestead.yaml
Once you have located the .yaml file, and opened in a code editor, edit the folders property of ~/.homestead/Homestead.yaml to share your code of both projects with VM:
folders:
- map: ~/yourproject1
to: /path/to/yourproject1
- map: ~/yourproject2
to: /path/to/yourproject2
Next, edit the sites property of Homestead.yaml to make Nginx enable the domain of both site:
sites:
- map: yourproject1.test
to: /home/vagrant/yourproject1/public
- map: yourproject2.test
to: /home/vagrant/yourproject2/public
Alternatively you can set your projects as subdomains of homestead.test
sites:
- map: yourproject1.homestead.test
to: /home/vagrant/yourproject1/public
- map: yourproject2.homestead.test
to: /home/vagrant/yourproject2/public
Also remember to edit your hosts file to forward these domain fo localhost
192.168.10.10 yourproject1.test
192.168.10.10 yourproject2.test
or (depending on which method you set them in Homestead.yaml) :
192.168.10.10 yourproject1.homestead.test
192.168.10.10 yourproject2.homestead.test
- In Terminal
cdinto your first original original project directory. - Run command
vagrant reload --provision. This will reload the vagrant machine so that the changes which we made in.yamlfile come in effect. You database of original project will remain intact. - Run
vagrant ssh - Run
lsand make sure you can see the folder of your new project. If its there you have configured your new site correctly. - Hit the url of new site with addition of
http://and your are DONE.
This concludes the tutorial on how to set up Homestead on a per prejoect basis, so that you can use multiple Laravel projects in it.



