arielcr
arielcr

Reputation: 1663

Laravel Homestead Multiple Sites

I have installed Laravel Homestead correctly, but now I want to add an additional site. I've done every step in the documentation, including editing my Homestead.yaml and my hostfile:

Homestead.yaml

---
ip: "192.168.10.10"
memory: 2048
cpus: 1

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

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

sites:
    - map: scp.dev
      to: /home/vagrant/Projects/scp
    - map: katniss.dev
      to: /home/vagrant/Projects/katniss

databases:
    - scp

variables:
    - key: APP_ENV
      value: local 

hostfile

192.168.10.10 scp.dev
192.168.10.10 katniss.dev

But when I run vagrant provision it displays this:

A Vagrant environment or target machine is required to run this command. Run vagrant init to create a new Vagrant environment. Or, get an ID of a target machine from vagrant global-status to run this command on. A final option is to change to a directory with a Vagrantfile and to try again.

Do I have to run this command on a specific folder?

Upvotes: 3

Views: 4252

Answers (4)

Amo
Amo

Reputation: 2944

A simpler one-command solution!

I stopped editing the homestead.yaml file, because like you I had a hard time getting changes to pick up. Now I just add new sites from within the VM itself. It's really easy, and the best part is that you don't need to re-provision your VM.

Simply SSH into your Homestead box:

vagrant ssh

Then, use the following command:

serve domain.com ~/Code/project/public

Obviously replacing domain.com with the domain you want to access the site via, and ~/Code/project/public with the full path of the public directory of your project.

Don't forget to then also edit your local hosts file, to add domain.com:

192.168.10.10 domain.com

With that done, your new site is now accessible via domain.com.

On newer versions of Homestead, the serve command may not be available. You can add it back, by going to your Homestead/scripts/ directory, and copying the serve-laravel.sh file to serve.sh.

Upvotes: 1

Kent Aguilar
Kent Aguilar

Reputation: 5368

You can use below option.

homestead.yaml

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

sites:
- map: scp.dev
  to: /home/vagrant/Projects/scp
- map: katniss.dev
  to: /home/vagrant/Projects/katniss

hostfile

192.168.10.10 scp.dev
192.168.10.10 katniss.dev

Assuming, your homestead was already halted, please run below command.

homestead up --provision

Try to access your new site again.

Upvotes: 0

Jawad
Jawad

Reputation: 95

I think an easier solution would be.

EPOCLAB:~ Dev$ homestead halt EPOCLAB:~ Dev$ homestead up --provision

Upvotes: 0

Bogdan
Bogdan

Reputation: 44586

Using vagrant provision without an ID requires the working directory to have a Vagrantfile generated with vagrant init. So for the command to work you need to:

cd /directory/with/Vagrantfile
vagrant provision

If you want to run the command from anywhere in your system, you can use any vagrant command that takes a target machine (such as up, halt, destroy, provision) with the ID of that machine. To get the available IDs just run:

vagrant global-status

And then:

vagrant provision MachineID

For more info check out the Vagrant Global Status Docs.

Upvotes: 8

Related Questions