In this section, we will use Vagrant's multi-machine feature to create a traditional web server and database setup. We will install our web server (nginx and PHP) on one machine and our database server (MySQL) on another.
This setup is simpler than the one in the previous section, but it should still help to reinforce how to set up and manage Vagrant multi-machine.
First, let's create a new Vagrantfile in a new folder. We will create two machines to get started, as follows:
Vagrant.configure("2") do |config|
# Configure web server machine
config.vm.define "web1" do |web1|
web1.vm.box = "ubuntu/xenial64"
web1.vm.network "private_network", ip: "10.0.0.50"
web1.vm.provision :shell do |shell|
shell.path = "web.sh"
end
end
# Configure database server machine
config.vm.define "db1" do |db1|
db1.vm.box = "ubuntu/xenial64"
db1.vm.network "private_network", ip: "10.0.0.51"
db1.vm.provision :shell do |shell|
shell.path = "db.sh"
end
end
end
Again, we will be using shell provisioning for these machines. We will be using the Ubuntu 16.04 box with private networking, and each machine will get its own private IP address.