Vagrant Server Management - Creating Websites
In this article, we'll set up a website on Centos 7 that includes an HTTPD service and HTML templates that we can access via the HTTP protocol. We'll also set up a second Ubuntu virtual machine to host a WordPress site. In addition, I'll show you how to use vagrant provisioning to automate this process.
Setting up a website on Centos 7
We can easily create a website in centos using predefined templates that are all accessible for free at "https://www.tooplate.com/".
The template I will use is "Wave Cafe", which you can download here


A better approach to handle this process is to download it directly to our VM:
Create a folder to host the new HTML template:
David@DESKTOP-VIK2BBH MINGW64 /c/vagrant-vms
$ mkdir wavecaffe
Initiate a new Centos VM:
David@DESKTOP-VIK2BBH MINGW64 /c/vagrant-vms/wavecaffe
$ vagrant init geerlingguy/centos7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
Configure an IP address to access the website in vagrantfile:

Start a new Centos Machine:
David@DESKTOP-VIK2BBH MINGW64 /c/vagrant-vms/wavecaffe
$ vagrant up
Log in and change user to Root:
David@DESKTOP-VIK2BBH MINGW64 /c/vagrant-vms/wavecaffe
$ vagrant ssh
[vagrant@localhost ~]$ sudo -i
[root@localhost ~]#
Install httpd package as a dependency to our HTML template:
[root@localhost ~]# yum install httpd wget unzip -y
wget - To download the template
unzip - To unzip the template
Start the httpd service and enable it after boot:
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Let's get the IPs we can use to access the server:
[root@localhost ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:da:d5:90 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s3
valid_lft 86002sec preferred_lft 86002sec
inet6 fe80::a00:27ff:feda:d590/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:3b:27:d4 brd ff:ff:ff:ff:ff:ff
inet 192.168.33.10/24 - Static IP brd 192.168.33.255 scope global noprefixroute enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe3b:27d4/64 scope link
valid_lft forever preferred_lft forever
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:b0:96:bb brd ff:ff:ff:ff:ff:ff
inet 192.168.5.149/24 - Router brd 192.168.5.255 scope global noprefixroute dynamic enp0s9
valid_lft 86002sec preferred_lft 86002sec
inet6 fe80::a00:27ff:feb0:96bb/64 scope link
valid_lft forever preferred_lft forever
And here is the default Apache HTTP page:

How can we change the default page?
We can edit the default site by accessing to the index.html file:
[root@localhost /]# cd /var/www/html/
[root@localhost html]# vi index.html

Restart server using [root@localhost html]# systemctl restart httpd

What is the best way to install the Wave-Cafe template on our server?
First, we need to get the download link of the package, we will do it by using F12 to get the real download link that we can use on our Linux machine:

Link: https://www.tooplate.com/zip-templates/2121_wave_cafe.zip
In Centos, Download to the TMP directory, and unzip file:
[root@localhost /]# cd tmp
[root@localhost tmp]# wget https://www.tooplate.com/zip-templates/2121_wave_cafe.zip
--2022-06-09 14:29:57-- https://www.tooplate.com/zip-templates/2121_wave_cafe.zip
Resolving www.tooplate.com (www.tooplate.com)... 69.16.201.107
Connecting to www.tooplate.com (www.tooplate.com)|69.16.201.107|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11896390 (11M) [application/zip]
Saving to: ‘2121_wave_cafe.zip’
[root@localhost tmp]# ls
2121_wave_cafe.zip
systemd-private-45c52bc8cf2d436fb716155dbef26661-chronyd.service-461yAy
systemd-private-45c52bc8cf2d436fb716155dbef26661-httpd.service-yVC2lm
[root@localhost tmp]# unzip 2121_wave_cafe.zip
result:
[root@localhost tmp]# ls
2121_wave_cafe systemd-private-45c52bc8cf2d436fb716155dbef26661-chronyd.service-461yAy
2121_wave_cafe.zip systemd-private-45c52bc8cf2d436fb716155dbef26661-httpd.service-yVC2lm
[root@localhost tmp]# cd 2121_wave_cafe
[root@localhost 2121_wave_cafe]# ls
css fontawesome img index.html js video
[root@localhost 2121_wave_cafe]#
Let's copy this content to the relevant folder and restart the service:
[root@localhost 2121_wave_cafe]# cp -r * /var/www/html/
cp: overwrite ‘/var/www/html/index.html’? y
[root@localhost 2121_wave_cafe]# systemctl restart httpd
And now the template is ready in the same IP:

Setting Up A WordPress Blog
The previous paragraphs focused on creating a static website; now it's time to go a step further and create a WordPress site. We'll start with a new virtual machine and work our way up to advanced configurations.
Step 1: Creating an ubuntu machine
As you saw in the previous example, I used the following code.
David@DESKTOP-VIK2BBH MINGW64 /c/vagrant-vms/wordpress
$ vagrant init ubuntu/bionic64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
Step 2: Networking
Let's use the vagrant file to define a static and public networks

and start the machine using the "vagrant up" command.
Step 3: Deployment of WordPress
To deploy WordPress on an ubuntu machine we can use an official guide

Install Dependencies:
vagrant@ubuntu-bionic:~$ sudo -i
root@ubuntu-bionic:~# sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
sudo apt install apache2 \
ghostscript \
libapache2-mod-php \
mysql-server \
php \
php-bcmath \
php-curl \
php-imagick \
php-intl \
php-json \
php-mbstring \
php-mysql \
php-xml \
php-zip -Y
Install Dependencies:
sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
Configure Apache for WordPress:
root@ubuntu-bionic:~# vim /etc/apache2/sites-available/wordpress.conf

And additional commands:
root@ubuntu-bionic:~# sudo a2ensite wordpress
Enabling site wordpress.
To activate the new configuration, you need to run:
systemctl reload apache2
root@ubuntu-bionic:~# systemctl reload apache2
root@ubuntu-bionic:~# sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
systemctl restart apache2
root@ubuntu-bionic:~# sudo a2dissite 000-default
Site 000-default disabled.
To activate the new configuration, you need to run:
systemctl reload apache2
root@ubuntu-bionic:~# sudo service apache2 reload
root@ubuntu-bionic:~#
Configure Database
$ sudo mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0,00 sec)
mysql> CREATE USER wordpress@localhost IDENTIFIED BY 'admin123';
Query OK, 1 row affected (0,00 sec)
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
-> ON wordpress.*
-> TO wordpress@localhost;
Query OK, 1 row affected (0,00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0,00 sec)
mysql> quit
Configure WordPress to connect to the database using the step-by-step guide
Step 4: Configure WordPress
We can now access the WordPress site using the static IP we set when we created the VM (http://192.168.33.60/), and customize the site according to your preferences.

You can now login under http://localhost/wp-login.php. just replace the localhost with the IP we set: http://192.168.33.60/wp-login.php