Are you tired of manually deploying your static websites? Do you wish there was a more efficient way to handle the deployment process? Well, look no further! In this blog post, I'll walk you through the steps of automating the deployment of a static website using Vagrant. ๐ค
Step 1: Create a Virtual Machine
Let's kick things off by creating a virtual machine with CentOS 9. Use Vagrant to initialize your project with the following command:
vagrant init eurolinux-vagrant/centos-stream-9
# You can use any linux distribution.
Step 2: Configure Network Settings
For easy access to your virtual machine, open both private and public networks. This allows you to access the VM using its IP address. Update your Vagrantfile with the appropriate network configuration.
config.vm.network "public_network"
config.vm.network "private_network", ip: "192.168.56.50"
# you can change the IP address, but be careful so they don't collide with some occupied ip
Step 3: Vagrant File Configuration
Now, let's configure the Vagrant file to set up the necessary dependencies for our static website. Include the following steps in your Vagrantfile:
config.vm.provision "shell", inline: <<-SHELL
yum update -y
yum install httpd unzip wget -y
systemctl start httpd
systemctl enable httpd
mkdir /tmp/finance
cd /tmp/finance
wget https://www.tooplate.com/zip-templates/2135_mini_finance.zip
unzip -o 2135_mini_finance.zip
cp -r 2135_mini_finance/* /var/www/html
cd /tmp
rm -rf /tmp/finance
SHELL
Step 4: Running the Virtual Machine
Execute the following command to bring up your virtual machine:
vagrant up
Vagrant will automatically provision the VM with the specified configurations and your website will get deployed within fraction of time.
Step 5: Fetch Ip Address and Hit that Ip in Browser
sudo ip addr show
#show the ip address of linux machine
Enjoy the seamless deployment - output
Conclusion
Congratulations! ๐ You've successfully automated the deployment of your static website using Vagrant. With just a few simple commands, you can now have your website up and running in no time. Feel free to customize the process further to suit your specific project needs.
Now go ahead, sit back, and watch Vagrant do the heavy lifting for you! Happy coding! ๐