Gregory Schultz
Gregory Schultz

Reputation: 844

How to get multi-machine Vagrant file to use one VM?

Is there a way to have a multi-machine setup where each config uses the same machine? I design websites and I would like to my VM to be configured to run as a webserver with an IP address and have each config to load the sync folder and domain name.

This is what I have so far:

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network :forwarded_port, host: 8080, guest: 80
config.vm.network "private_network", ip: "172.28.128.3"

config.vm.define "myoffercode" do |vm1|
    vm1.vm.synced_folder "/Users/gregoryschultz/Sites/myoffercode", "/var/www/html"
end

config.vm.define "dailybayou" do |vm2|
    vm2.vm.synced_folder "/Users/gregoryschultz/Sites/dailybayou", "/var/www/html"
end
end

Thanks for the help,

Upvotes: 0

Views: 287

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53703

Is there a way to have a multi-machine setup where each config uses the same machine?

no you can't, 1 config machine = 1 VM so when you write

config.vm.define "myoffercode" do |vm1|
    vm1.vm.synced_folder "/Users/gregoryschultz/Sites/myoffercode", "/var/www/html"
end

it really creates a new VM managed by vagrant

I design websites and I would like to my VM to be configured to run as a webserver with an IP address and have each config to load the sync folder and domain name.

The solution will be to use 1 VM and using Virtual hosts

so in your VM you sync all your project

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network :forwarded_port, host: 8080, guest: 80
  config.vm.network "private_network", ip: "172.28.128.3"

  config.vm.synced_folder "/Users/gregoryschultz/Sites/myoffercode", "/var/www/html/myoffercode"
  config.vm.synced_folder "/Users/gregoryschultz/Sites/dailybayou", "/var/www/html/dailybayou"
end

and in your configuration of Apache

# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
    DocumentRoot "/var/www/html/dailybayou"
    ServerName dailybayou.localdev

    # Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/html/myoffercode"
    ServerName myoffercode.localdev

    # Other directives here
</VirtualHost>

make sure to update your local host file to point 172.28.128.3 to those websites

Upvotes: 2

Related Questions