6.Wordpress-web-solution

msql, apache, php, wordpress

In this project we will prepare a storage infrastructure on two Linux servers and implement a basic web solution using WordPress. We will use mysql database for its backend Relational Database Management System.

This project will display the full concept of the three-tier architecture upon which web solutions are biult:

  1. Presentation Layer: This is the clients browser, smartphone or laptop.

2: Business Layer: This stands for the backend component that implements business logic. Theses are the servers or application.

  1. Data Access or Management Layer (DAL): This is the layer for computer data storage and data access. Database Server or File System Server such as FTP server, or NFS Server.

Screenshot from 2023-03-10 18-35-26

REDHAT Os will be used for this project

CONFIGURE 2 CENTOS SERVERS AND LAUNCH THEM

instance

For the Database server(DB-cent)

Navigate to the volume section and create 3 volumes, 10G each in the same availability zone of the created insances

createvol

Click on the created volumes, one after the other and attach them to the Database server

Open terminal and verify for the attached volumes

lsblk

lsblkdb

To see all mounts and free space on your server: Run:

df -h

Create a single partition on each of the 3 disks using gdisk utility

sudo gdisk /dev/xvdf sudo gdisk /dev/xvdg sudo gdisk /dev/xvdh

gdiskxvdf

Type n to create new partition, 1 to indicate the number, p to check the partition created and w to write the partition and type y for yes to complete the partition

Run lsblk to see the new partitions

lsblkpart

To check the available volume, we will user lvm2

Install lvm3. Run:

sudo yum install lvm2 Check the available volume . Run:

sudo lvmdiskscan

physicalvol

Use pvcreate utility to mark each of 3 disks as physical volumes (PVs) to be used by LVM Run:

sudo pvcreate /dev/xvdf1
sudo pvcreate /dev/xvdg1
sudo pvcreate /dev/xvdh1

Confirm the volumes are created, Run:

sudopvs

This shows the physical volumes have been marked

Create a volume group using vgcreate, name of the group here is webdata-vg

sudo vgcreate webdata-vg /dev/xvdf1 /dev/xvdg1 /dev/xvdh1

Run sudo vgs to confirm the created volume group

vgcreatendsudo

Next, we use lvcreate to create 2 logical volumes to store web data and logs. Apps-lv and logs-lv respectively

sudo lvcreate -n apps-lv -L 14G webdata-vg
sudo lvcreate -n logs-lv -L 14G webdata-vg

Run:

sudo lvs to see the logical volumes created

lvndsudo

Run sudo lsblk to check the entire created volumes

createsummary

Use mkfs.ext4 to format the logical volumes with ext4 filesystem

sudo mkfs -t ext4 /dev/webdata-vg/apps-lv
sudo mkfs -t ext4 /dev/webdata-vg/logs-lv

formatext4

Create /var/www/html directory to store website files

sudo mkdir -p /var/www/html

Create /home/recovery/logs to store backup of log data

sudo mkdir -p /home/recovery/logs

Mount /var/www/html on apps-lv logical volume

sudo mount /dev/webdata-vg/apps-lv /var/www/html/

We use rsync utility to backup all the files in the log directory /var/log into /home/recovery/logs. We do this before mouting on the /var/log because evrything on the directory will be formatted upon mounting leading to loss of valuable data.

sudo rsync -av /var/log/. /home/recovery/logs/

backuplog

Now, we mount on /var/log directory

sudo mount /dev/webdata-vg/logs-lv /var/log

Return the backed files from /home/recovery/logs

sudo rsync -av /home/recovery/logs/. /var/log

Next we update the /etc/fstab file

Run:

sudo blkid

blkid

Next, update /etc/fstab

sudo vi /etc/fstab

fstabedit

Mount and reload daemon

sudo mount -a
sudo systemctl daemon-reload

Use df -h to see the total

PREPARE THE DATABASE 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/.

Install WordPress on your Web Server EC2

sudo yum -y update

Install wget, Apache and it’s dependencies

sudo yum -y install wget httpd php php-mysqlnd php-fpm php-json

Start Apache

sudo systemctl enable httpd
sudo systemctl start httpd

To install PHP and it’s depemdencies

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo yum module list php
sudo yum module reset php
sudo yum module enable php:remi-7.4
sudo yum install php php-opcache php-gd php-curl php-mysqlnd
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
setsebool -P httpd_execmem 1

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
  cp wordpress/wp-config-sample.php wordpress/wp-config.php
  cp -R wordpress /var/www/html/

Install MySQL on your DB Server EC2

sudo yum update
sudo yum install mysql-server

Screenshot from 2023-03-10 23-52-15

Check the status if the service is running. Run

sudo systemctl status mysqld

To start and enable mysqld, Run:

sudo systemctl restart mysqld
sudo systemctl enable mysqld

Configure 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;
exit

mysqluser

Screenshot from 2023-03-10 23-10-29

Configure WordPress to connect to remote database

open MySQL port 3306 on DB Server EC2, also, set the ip address to the public address of the webserver and add /32 to it

ec2mysql

Install MySQL client and test that we can connect the database server from the webserver.

sudo yum install mysql
sudo mysql -u admin -p -h <DB-Server-Private-IP-address>

On mysql show database to confirm if you can see the database created on the webserver

dbconfirm

Change permissions and configuration so Apache could use WordPress:

Configure SELinux 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

Enable TCP port 80 in Inbound Rules configuration for your Web Server EC2 from anywhere 0.0.0.0/0 or system ip

Screenshot from 2023-03-10 23-35-26

Screenshot from 2023-03-10 23-36-26

END