Vagrant multiple servers


In this tutorial, How to deploy multiple servers using Vagrant. I will deploy LAMP multiple servers. I create more VMs, each VM can have its own and different configuration.

My Environment

  • Host OS: Window 11
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell

LAMP server architecture

image 10

Vagrant directory and files will look like as below:

│   Vagrantfile


I created script to deploy the common packages as below


#Update OS
# sudo yum update -y --exclude=kernel

sudo yum install -y git unzip nc telnet script to install the package Apache, PHP as below


sudo dnf install -y httpd httpd-devel httpd-tools

#chkconfig --add httpd
sudo systemctl enable httpd.service
sudo systemctl stop httpd

sudo systemctl start httpd

sudo dnf install -y php php-cli php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd script to install MySQL server as below


sudo yum install -y mysql mysql-server mysql-devel
sudo systemctl enable mysqld.service
sudo systemctl start mysqld

mysql -u root -e "SHOW DATABASES";

Create a Virtual Machine

Navigate to my working directory

cd Rocky-LAMP
vagrant init rockylinux/8

Configure the Virtual Machine

Edit the Vagrantfile and paste the content below

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config| = "rockylinux/8"
  config.ssh.insert_key = false  
  config.vm.provision "shell", 
   path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\VM-multi-server\\shell\\"

  config.vbguest.auto_update = false
  config.vm.define "webserver" do |webserver|
    webserver.vm.hostname = "" "private_network", ip: "" "forwarded_port", guest: 80, host: 8888
    webserver.vm.provision "shell", 
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\VM-multi-server\\shell\\"


  config.vm.define "databases" do |databases|
    databases.vm.hostname = "database-server" "private_network", ip: ""
    databases.vm.provision "shell", 
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\VM-multi-server\\shell\\"



Deploy LAMP on Rocky Linux

vagrant up

To connect to Web Server.

vagrant ssh webserver
image 11

To connect to the database server.

vagrant ssh databases
image 12

Opens a browser that can access your Server’s IP address

image 13


You have to use Vagrant to install LAMP for multiple servers. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.