Setting Up a Website with Vagrant and CentOS
Introduction
In my learning path of DevOps, today I delved into the realm of setting up a website using Vagrant and CentOS. As the digital landscape evolves, the ability to swiftly deploy and manage development environments becomes increasingly crucial for efficient software development. Vagrant, a tool that streamlines this process by automating the setup of virtual machines, coupled with the reliability and robustness of CentOS, a popular Linux distribution. Let's dive into the steps I explored today in bringing a website to life within this environment.
Prerequisites
Vagrant installed in your system
Basic understanding of the CLI (Command Line Interface)
Hypervisor like VirtualBox and VMware installed
Setting up Vagrant with Centos
Create a new directory for your project and navigate into it
Now, initialize a new Vagrant environment with a CentOS box
Configuration of VM
Once done open the vagrant file either in the VIM editor or in any editor of your choice
Uncommand all the necessary configuration and edit the Vagrantfile based on your requirements
Start the VM
Use the below command to start the VM
vagrant up
Connect to the Virtual Machine
Use the below command to connect to the VM
vagrant ssh
Setup Web Server
Install the necessary packages
yum install httpd vim unzip zip -y
Once installed start and enable the service of webserver
systemctl start httpd
The above command will start the service but if the system is rebooted then the service will turf off automatically in order to prevent this we will be enabling it so that it will turn on automatically after rebooting
To enable the service
systemctl enable httpd
Once the above step is done if we access the website using http://systemip we will get a page like this
Now the content of the webpage must be put in the directory /var/www/html to get reflected in the website
Downloading a HTML template
Go to tooplate.com and get the link of download file of your favorite html template and unzip those files
In order to get the zip file link open your favorite template and then press F12 key and navigate to the network section
Press the download button and cancel the download pop up to get the link of the zip file
Navigate to temporary directory by
cd /tmp/
copy the link and use the below command to download the zip file in our centos VM in my case i have download a barista cafe html template
wget https://www.tooplate.com/zip-templates/2137_barista_cafe.zip
Setting up the website
Now to unzip the zip file use the below command
unzip 2137_barista_cafe.zip
Now get into the directory
cd 2137_barista_cafe/
List all the files by ls command
Now as discussed earlier we have to store the content in the /var/www/html/ directory for it to get reflected in the website.
So we have to copy all the files to the /var/www/html directory
To copy file use the below command
cp -r * /var/www/html
-r -> This option is used to copy directories and their contents recursively.
* -> This option is used to copy all the files in this directory
Once copied it is necessary to restart the httpd service
systemctl restart httpd
Accessing the website
Once all the steps are done we can access our website by Systemip of VM (eg: http://192.168.**.**)
Conclusion
In this guide, we've covered the process of setting up a website using Vagrant and CentOS. By following these steps, you can quickly create a development environment for your web projects and start building and testing websites with ease. Vagrant's simplicity and flexibility make it an excellent choice for managing development environments, while CentOS provides a stable and reliable platform for hosting web applications.