In this blog, our objectives are as follows -
🔅 Create an AWS EC2 instance
🔅 Configure the instance with Apache Webserver.
🔅 Download PHP application name “WordPress”.
🔅 As WordPress stores data at the backend in the MySQL Database server, therefore, you need to set up a MySQL server using AWS RDS service using Free Tier.
🔅 Provide the endpoint/connection string to the WordPress application to make it work.
So, let’s get going with the job in hand.
Launch an EC2 Instance on AWS
Firstly, we need to launch an EC2 Instance on AWS which we will use to configure Apache Webserver and run WordPress.
Launching the instance is very simple and is not part of our agenda, so we will quickly launch the instance-
As we can see, our instance named WordPress-RHEL8 is ready to use.
Then, we will work on the instance remotely using SSH from our local Windows device. We are using the OpenSSH inbuilt in Windows. We will login using our Public Key and Public IP as follows:
Configure the EC2 Instance
We would be needing the following software for configuring WordPress -
So let’s configure them one by one.
▶️ Configuring PHP:
For this demo, we will be needing PHP version 7.4 or above. Now we will be using the Remi repository to get these packages.
But, the Remi repo has some dependencies from the EPEL Repo. So we need to first install the EPEL Repo followed by Remi Repo
Command to Install EPEL Repo:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Command to Install Remi Repo:
yum install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Now, we have both the Repositories ready to use. Next is installing the PHP packages (php7.4 & php-mysqlnd) :
dnf module install php:remi-7.4
dnf install php-mysqlnd
▶️ Configuring MySQL:
We must have a data database for using WordPress. Here, we will be using MySQL in the back end and for that, we must have a MySQL program in the frontend as well to contact the server.
Command to install mysql:
dnf install mysql
▶️ Configuring httpd & wget:
Finally, we need to install the httpd (to get Apache Webserver) and the wget in this instance.
Command to install httpd:
dnf install httpd
Command to install wget:
dnf install httpd
Now the task will be to set the endpoint to our MySQL server hosted on Amazon RDS. But for that, we need to first configure the Amazon RDS.
Configure Amazon RDS
Amazon RDS stands for Amazon Relational Database Service. Amazon RDS is a distributed relational database service by Amazon Web Services. It is a web service running “in the cloud” designed to simplify the setup, operation, and scaling of a relational database for use in applications.
▶️ Configuring MySQL Server on RDS:
First, we have to move to the RDS Console on AWS and press Create Database. Then, follow the below steps-
- Choose Standard Create & MySQL as our DB
2. Choose MySQL Version 5.7.31
We will use this version as it has Free Tier access, is stable and WordPress can use it.
3. Name your DB instance, set a username & password for the master
This we will use to login to our DB.
4. Setting Storage
We will use General Purpose SSD with 20 GB storage. It is enough for our demo.
We are using the default VPC here.
Also, we are creating a new VPC Security Group that we will configure later. Also, we will use Password authentication.
6. Setting Initial DB Name
We will keep the rest of the settings as default settings and create the database.
7. Configure Security Group
The VPC Security Grp that we have created has to be configured. We need to edit its Inbound Rules such that only the WordPress Instance can connect to it.
Finally, our RDS DB is launched & is ready to use.
▶️ Logging into the MySQL Server
We will use the following command to login to the MySQL on RDS -
mysql -h <endpoint_url_of_db> -u <user_name_of_db> -p
So, we have successfully logged in to the MySQL Server.
Now, we can run some commands to check if everything is working.
We can also see that our initial database db_wordpress is present.
Start httpd Server
Setup WordPress on Apache Server
▶️ Download PHP file for WordPress (using wget)
The PHP file will be downloaded in tar format, which we need to unpack and store at the document root of the Webserver, i.e., /var/www/html
▶️ Setup the WordPress
We can see that nobody is owning WordPress.
So we need to use the chown -R apache:apache * command to make the Apache service to own WordPress.
Also, the SELinux might not be allowing the services like httpd to have write permissions.
Security-Enhanced Linux (SELinux) is a security architecture for Linux systems that allows administrators to have more control over who can access the system.
If the SELinux is Enforcing, we have to change it to Permissive mode, by ‘setenforce 0’.
Login to WordPress from Browser
We need to type in the Public IP of the EC2 Instance with the WordPress server.
▶️ Enter Credential
Enter db_name, username, password, db_endpoint and submit.
▶️ Run the Installation
Enter the user data that you will use to login to our WordPress a/c.
▶️ Login to WordPress a/c
The above is the dashboard that we will get when we log in.
Let’s write our first blog/article on WordPress to see if everything is working fine.
Now, let’s check manually into our SQL DB on Amazon RDS if everything has been recorded there.
After logging into our MySQL server, we need to select our DB, i.e., db_wordpress and then check the tables-
As we can see, all our WordPress data is being reflected here and it confirms that everything is working fine.
So, we have come to the end of this demo. Hope this has helped you in some way.
Thank you for stopping by.