In this article, I’ll show how to set up WordPress(frontend) and AWS RDS database step by step.
Description:
🔅 Create an AWS EC2 instance and configure it with Apache web server and compatible PHP and MYSQL environment
🔅 Download and configure PHP-based application name “WordPress”.
🔅 WordPress stores data at the backend in the MySQL Database Server. Therefore, you need to set up a MySQL server using the AWS RDS service.
🔅 Provide the endpoint string to the WordPress application to connect with RDS and make it work.
First things first, let’s create an EC2 instance from the console and configure the Apache webserver.
I’ve used RHEL8 AMI throughout and performed the task by following all the dependencies. Manually performed all the steps but the same setup can be(should be) done using IaC tools like Terraform.
→SSH to the instance and run the following commands to install httpd, PHP, and MySQL(with dependencies) and start the services:
yum module install httpd php mysql
yum install php-mysqlnd
systemctl start httpd
httpd, PHP, MySQL installed and service started for httpd
→ Install the latest version of WordPress(written in PHP)and copy the same in the document root of the httpd(/var/www/html) in the system:
[https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz) --output wordpress.tar.gz //install wordpress
tar xf wordpress.tar.gz //extract the downloaded file
cp -rv wordpress /var/www/html // copy the content in doc. root
->If all the above steps are successful then we can access the front end with public-ip/wordpress and the o/p will look like this:
Default page after installation
Leave this till here and let’s configure the AWS RDS database from the console
→AWS RDS offers various flavors of relational databases that include MySQL, MariaDB, PostgreSQL, Oracle, Microsoft SQL Server, and Amazon Aurora. RDS is a fully managed service from AWS, so users have to only focus on data and databases.
After selecting the database engine and creation method, set the instance name and admin user and password.
Now select compute and storage unit for the DB instance as per requirement. I have used the free-tier RDS method, so t2.micro flavor and default storage type is selected.
As a next step, select network set up for the instance. I have taken default VPC and subnet. Usually, the database is running in the backend of our application and is not meant for public access. So, it’s suggested to disable public access of RDS. As a security group, good practice to open the specific port and allow only admin IP.
Still, there are additional options that give more customization and post-launch actions. Totally depends on the requirement which facilities you need. I’ve left the else part default. Click on Create Database to launch the RDS.
It takes around 10 mins to launch the DB cluster. As this is a fully managed service, the user need not configure anything.
→Let’s connect to the RDS instance with the unique endpoint. I am using an ec2 instance within the vpc of RDS. So, being in the same network, we can connect.
Use the syntax mysql -h -u -p and pass the password on prompt.
Now create a database to further connect with the WordPress site. Use the syntax create database
→Database created. Now let’s head towards the WordPress dashboard where we left and pass the above database name, username, password, and instance endpoint on that screen.
On submit, internally it will write the above entries in the wp-config file and connect the front-end to the backend database. On a successful connection, the user will have to fill in the WordPress site details and dashboard login details. Run the WordPress installation when done.
😇Perfect. Each requirement for our problem statement is fulfilled. The below screen implies a successful installation and connection with the database. Here, all the user data is stored in a very reliable and powerful RDS instance. So even if the front-end goes down, the most critical user data won’t lose.
That’s all I have for this article. Thanks a lot for reading.🤗
I’ll be grateful to have connections like you on Linkedl *n * 🧑💼
Top comments (0)