Generally, web, or mobile solutions are implemented based on what is called the Three-tier Architecture.
Three-tier Architecture is a client-server software architecture pattern that comprise of 3 separate layers.
Your 3-Tier Setup
- A Laptop or PC to serve as a client
- An VM Linux Server as a web server (This is where you will install WordPress)
- An VM Linux server as a database (DB) serve
The managed disk will be used as data disk for the virtual machine.
The VM will serve as a Web Server, create/attach the two managed disk earlie created in the same AZ as the Web Srver VM, each of 16GB.
sudo apt update && sudo apt upgrade -y4. Use lsblk command to inspect what block devices are attached to the server. Notice names of your newly created devices.
- All devices in Linux reside in
/dev/directory. - Inspect it with ls /dev/ and make sure you see all 3 newly created block devices there – their names will likely be
sda,sdb,sdc, etc. - In my case, they are
sda,sdd. Wheresdbis the OS disk,sdais the first data disk andsddis the second data disk.
sudo gdisk /dev/sda
sudo gdisk /dev/sdd- Run
sudo lvmdiskscancommand to check for available partitions.
pvcreate /dev/sda1
pvcreate /dev/sdd1 sudo vgcreate webdata-vg /dev/xvdh1 /dev/sda1 /dev/sdd1 sudo vgsapps-lv (Use half of the PV size), and logs-lv Use the remaining space of the PV size.
NOTE: apps-lv will be used to store data for the Website while, logs-lv will be used to store data for logs.
sudo lvcreate -n apps-lv -L 15G webdata-vg
sudo lvcreate -n logs-lv -L 15G webdata-vgsudo mkfs -t ext4 /dev/webdata-vg/apps-lv
sudo mkfs -t ext4 /dev/webdata-vg/logs-lvsudo mkdir -p /var/www/htmlsudo mkdir -p /home/recovery/logssudo mount /dev/webdata-vg/apps-lv /var/www/html/19. Use rsync utility to backup all the files in the log directory /var/log into /home/recovery/logs
- (This is required before mounting the file system)
sudo rsync -av /var/log/. /home/recovery/logs/- (Note that all the existing data on /var/log will be deleted. That is why step 15 above is veryimportant)
sudo mount /dev/webdata-vg/logs-lv /var/log sudo rsync -av /home/recovery/logs/. /var/log22. Update /etc/fstab file so that the mount configuration will persist after restart of the server.
UPDATE THE /ETC/FSTAB FILE
The UUID of the device will be used to update the /etc/fstab file;
sudo blkidsudo vi /etc/fstab- Update /etc/fstab in this format using your own UUID and rememeber to remove the leading and ending quotes.
Test the configuration and reload the daemon
sudo mount -a
sudo systemctl daemon-reload- Verify your setup by running df -h, output must look like this:
Launch a second Linux VM instance – ‘DB Server’
Repeat the same steps as for the Web Server, but instead of apps-lv create db-lv and mount it to /db directory instead of /var/www/html/.
- Update the repository
sudo apt -y update- Install Apache
sudo apt install apache2- Start Apache
sudo systemctl start apache2To install PHP and it’s depemdencies
Restart Apache
sudo systemctl restart httpd- Download wordpress and copy wordpress to var/www/html
mkdir wordpress
cd wordpress
sudo wget http://wordpress.org/latest.tar.gz
sudo tar xzvf latest.tar.gz
sudo rm -rf latest.tar.gz
sudo cp wordpress/wp-config-sample.php wordpress/wp-config.php
sudo cp -R wordpress /var/www/html/- Configure Linux Policies
sudo chown -R apache:apache /var/www/html/wordpress
sudo chcon -t httpd_sys_rw_content_t /var/www/html/wordpress -R
sudo setsebool -P httpd_can_network_connect=1- Install MySQL on your DB Server EC2
sudo apt update
sudo apt install mysql-serverVerify that the service is up and running by using sudo systemctl status mysqld, if it is not running, restart the service and enable it so it will be running even after reboot:
sudo systemctl restart mysqld
sudo systemctl enable mysqldConfigure DB to work with WordPress
sudo mysql
CREATE DATABASE wordpress;
CREATE USER `myuser`@`<Web-Server-Private-IP-Address>` IDENTIFIED BY 'mypass';
GRANT ALL ON wordpress.* TO 'myuser'@'<Web-Server-Private-IP-Address>';
FLUSH PRIVILEGES;
SHOW DATABASES;
exitConfigure WordPress to connect to remote database.
Hint: Do not forget to open MySQL port 3306 on DB Server. For extra security, you shall allow access to the DB server ONLY from your Web Server’s IP address, so in the Inbound Rule configuration specify source as /32
Install MySQL client and test that you can connect from your Web Server to your DB server by using mysql-client
sudo apt install mysql
sudo mysql -u admin -p -h <DB-Server-Private-IP-address>Verify if you can successfully execute SHOW DATABASES; command and see a list of existing databases.
Change permissions and configuration so Apache could use WordPress:
Enable TCP port 80 in Inbound Rules configuration for your Web Server EC2 (enable from everywhere 0.0.0.0/0 or from your workstation’s IP)
Try to access from your browser the link to your WordPress http://<Web-Server-Public-IP-Address>/wordpress/

















