How To Setup Local Server Like Lab Using Vagrant And Oracle Virtual Box On Windows

Embark on the journey of creating a personalized local server lab using Vagrant and Oracle VirtualBox with our comprehensive guide. Learn how to seamlessly set up a virtualized environment that mirrors real-world server scenarios for testing and development purposes. Our step-by-step instructions cater to both beginners and experienced users, ensuring a smooth and efficient setup process. Dive into the world of Vagrant and Oracle VirtualBox to create a versatile local server lab, facilitating experimentation and innovation without impacting your production environment. Follow our detailed guide to harness the power of virtualization, enabling you to build, test, and refine your server configurations with ease. Elevate your development experience by mastering the art of setting up a local server lab using Vagrant and Oracle VirtualBox
Prerequisite:
- Windows 11
- Oracle Virtual Box: 7.0.10 or higher
- Chocolatey: 2.2.0 or higher
To install the Oracle virtual box you can refer to this link.
Installing Chocolatey
First, ensure that you are an administrator and using PowerShell or CMD as Adminstrator
win + s -> search “PowerShell” -> select Run As Administrator
Run this command to install Chocolatey Community Edition.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
choco install vagrant
choco install vagrant
Setting Up the server like Lab.
- Step 1 : Make a directory where you want just make sure that the drive has the enough storage where you are making the directory. eg., Folder-Name* : Vagrant
- Step 2: Make a File named as Vagrantfile
- Step 3: Now open the file in any Text Editor (notepad, VsCode etc…)
- Step 4: Add these snippets for making Linus Distros server lab inside Vagrantfile
Vagrant.configure("2") do |config|
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
### Nginx VM ###
config.vm.define "server" do |server|
server.vm.box = "ubuntu/jammy64"
server.vm.hostname = "server"
server.vm.network "private_network", ip: "192.168.56.15"
# Increase RAM allocation to 3GB
server.vm.provider "virtualbox" do |vb|
vb.memory = 3048
vb.cpus = 2
end
end
end
Note: You can change the memory usage as you want 2GBs * 1024MBs => 2048
Note: You can change the CPUs you want eg., 2, 3, 4 etc…
Note: You can change the distro from ubuntu to centos
server.vm.box = "centos/8" //centos 8
server.vm.box = "eurolinux-vagrant/centos-stream-9" //centos 9
Note: This IP can be changed as you want: 192.168.56.15
- Step 5: Use this command to bring up the environment. Make sure that the Oracle VM box is running and you should be inside that folder where you have made the Vagrantfile
vagrant up
This will take a few minutes to bring up the environment depending upon your Internet Speed
- Step 5: Connect with the vagrant machine
vagrant ssh
Now do your stuff, this will be the isolated and private server for you which is not public.
- Step 6: To gracefully shut down the vagrant Machine
vagrant halt
Step 7: To destroy the vagrant machine
vagrant destroy
All Commands should be used in the same directory.
: – For the particular machine configuration of the vagrant machine
vagrant config