Wednesday, 27 September 2017

how to develop multi project at the same time in homestead?

You may know how to setup the homestead development environment and understand how to develop a project under homestead. But, if you need develop more than one project in the same homestead at the same time, it could confuse you.

Now, let's finger out how to develop more project on homestead step by step.

1. You may have the folder like /home/vagrant/Code or /home/vagrant/Code/public in your VM dependant on the Homestead.yaml setting.

2. using composer install the laravel framework. If we say the homestead is the VM, environment of development. laravel framework is the folder contractor of development.

In your VM, type these command is a ssh terminal.
composer create-project laravel/laravel quickstart --prefer-dist

notes: laravel/laravel means using larvel framework, quickstart is the folder of the project.

3. Back to your home machine which installed vagrant. Open file Homestead.yaml is the Homestead folder.

Config-rate sites for different project. 
sites:
    - map: homestead.app
      to: /home/vagrant/Code/public/quickstart/public
    - map: TaskManagement.app
      to: /home/vagrant/Code/public/taskManagement/public

databases:
    - homestead
    - tasks

Each project has its own site and using different database.

4. Open the hosts config file on your host machine. For windows, it is  c:\windows\system32\drivers\etc\hosts,

192.168.10.10 homestead.app
192.168.10.10 TaskManagement.app

means, if you type homestead.app, it will map to site 192.168.10.10 /home/vagrant/Code/public/quickstart/public

if you type TaskManagement.app, it will map to site 192.168.10.10 /home/vagrant/Code/public/taskManagement/public

5. Back to your VM. enter the project quickstart folder
\home\vagrant\Code\public\quickstart\
Use ls -a, list all the files, including the hidden files, you will see a file named .env, open it.

You should see these lines;

DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

homestead is the database which quickstart project is using. homestead is the username which using to connect to the database, secret is the password.

OK, quit and don't change anything.

Enter project TaskManagement folder
\home\vagrant\Code\public\taskManagement\
Again, use ls -a, open .env file

DB_DATABASE=tasks                     //    change the database to which you want
DB_USERNAME=homestead
DB_PASSWORD=secret

It should change the environment without restart your VM. But, if it doesn't work. Use vagrant halt and vagrant up to active setting.

Now, the sites and databases are suit for multi project development.

Enjoy!!!





No comments:

Post a Comment