-
Launch an EC2 instance that will serve as "Web Server". Create 3 volumes in the same AZ as your Web Server EC2, each of 10 GiB.
-
Attach all three volumes one by one to your Web Server EC2 instance
-
Open up the Linux terminal to begin configuration of the instance. Use
lsblk
command to inspect what block devices are attached to the server. The 3 newly created block devices are names xvdf, xvdh, xvdg -
Use
df -h
command to see all mounts and free space on your server -
Use gdisk utility to create a single partition on each of the 3 disks
sudo gdisk /dev/xvdf
-
A prompt pops up, type n to create new partition, enter no of partition(1), hex code is 8e00, p to view partition and w to save newly created partition.
-
Repeat this process for the other remaining block devices.
-
Install lvm2 package by typing: sudo yum install lvm2. Run
sudo lvmdiskscan
command to check for available partitions. -
Create physical volume to be used by lvm by using the pvcreate command:
sudo pvcreate /dev/xvdf1
sudo pvcreate /dev/xvdg1
sudo pvcreate /dev/xvdh1
-
Next, Create the volume group and name it webdata-vg:
sudo vgcreate webdata-vg /dev/xvdf1 /dev/xvdg1 /dev/xvdh1
-
Create 2 logical volumes using lvcreate utility. Name them: apps-lv for storing data for the Website and logs-lv for storing data for logs.
sudo lvcreate -n apps-lv -L 14G webdata-vg
sudo lvcreate -n logs-lv -L 14G webdata-vg
- Verify Logical Volume has been created successfully by running:
sudo lvs
- Next, 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
-
Next, create mount points for logical volumes. Create /var/www/html directory to store website files:
sudo mkdir -p /var/www/html
and mount /var/www/html on Mount /var/www/html on apps-lv logical volume :sudo mount /dev/webdata-vg/apps-lv /var/www/html/
-
Then create /home/recovery/logs to store backup of log data:
sudo mkdir -p /home/recovery/logs
-
Use rsync utility to backup all the files in the log directory /var/log into /home/recovery/logs (It is important to backup all data on the /var/log directory because all the data will be deleted during the mount process) Type the following command:
sudo rsync -av /var/log/. /home/recovery/logs/
-
Mount /var/log on logs-lv logical volume:
sudo mount /dev/webdata-vg/logs-lv /var/log
-
Finally, restore deleted log files back into /var/log directory:
sudo rsync -av /home/recovery/logs/. /var/log
-
Next, update /etc/fstab file so that the mount configuration will persist after restart of the server.
-
The UUID of the device will be used to update the /etc/fstab file to get the UUID type:
sudo blkid
and copy the both the apps-vg and logs-vg UUID (Excluding the double quotes) -
Type sudo
vi /etc/fstab
to open editor and update using the UUID you copied. -
Test the configuration and reload the daemon:
sudo mount -a`
sudo systemctl daemon-reload
- Launch a second RedHat EC2 instance and name it 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 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
- 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/
- 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
- Runn the following:
sudo yum update
sudo yum install mysql-server
- Verify that the service is up and running by using
sudo systemctl status mysqld
. If the service is not running, restart the service and enable it so it will be running even after reboot:
sudo systemctl restart mysqld
sudo systemctl enable mysqld
- Configure DB to work with Wordpress with the code below.
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
- Make sure to open MySQL port 3306 on DB Server EC2. 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 yum 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:///wordpress/