Combining Amazon RDS with WordPress

Objective:-

πŸ”… Create an AWS EC2 instance

πŸ”… Configure the instance with Apache Webserver.

πŸ”… Download php application name β€œWordPress”.

πŸ”… As wordpress stores data at the backend in MySQL Database server. Therefore, you need to setup a MySQL server using AWS RDS service using Free Tier.

πŸ”… Provide the endpoint/connection string to the WordPress application to make it work

What is Wordpress?

WordPress is the simplest, most popular way to create your own website or blog. In fact, WordPress powers over 39.5% of all the websites on the Internet. Yes β€” more than one in four websites that you visit are likely powered by WordPress.

On a slightly more technical level, WordPress is an open-source content management system licensed under GPLv2, which means that anyone can use or modify the WordPress software for free. A content management system is basically a tool that makes it easy to manage important aspects of your website β€” like content β€” without needing to know anything about programming.

The end result is that WordPress makes building a website accessible to anyone β€” even people who aren’t developers.

Amazon RDS service

Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching and backups. It frees you to focus on your applications so you can give them the fast performance, high availability, security and compatibility they need.

Amazon RDS is available on several database instance types β€” optimized for memory, performance or I/O β€” and provides you with six familiar database engines to choose from, including Amazon Aurora, PostgreSQL, MySQL, MariaDB, Oracle Database, and SQL Server. You can use the AWS Database Migration Service to easily migrate or replicate your existing databases to Amazon RDS.

1.Configuring Database as a service

For setting up database in the amazon there is service named RDS under the database section . After clicking we will land to the dashboard page from where select the create database option and follow the steps or customize it according to your need.

First selecting the creation method we will select standard create because it provides more option to customize. Then will go with the MySQL datatype.

selecting database

After selecting the type select the required version of the datatype, here I selected 5.7.31.

Also select the template according to your need, this is for just practice Free tier is selected.

Now provide the credential setting that is username and password for authentication.

Since it is a free tier so we cant select the db instance type.

Now specifying the minimum allocated storage and maximum threshold storage.

Now there is need to provide the connectivity details here such as VPC to be used and security group and also about the public access for database.

In the additional information a name will be provided and the database with this name will already be created when the it is launched.

And thus click on create database button. The database will be successfully launched.

2.Configuring EC2 instance as Web server

For the ec2 instance redhat linux AMI will be used.

selecting redhat AMI
ec2 launched successfully

Now for the configuring this instance as a web server there is need of software named as httpd and it can be installed with the help of yum.

#yum install httpd

First there is need of wget package for downloading different packages over internet. It can be installed with the help of yum .

#yum install wget

installing wget

There are also some requirements for wordpress :-

PHP version 7.4 or greater.

MySQL version 5.6 or greater OR MariaDB version 10.1 or greater.

The php 7 or greater packages available in different repositories one of them is REMI and this REMI repository depends upon the EPEL repository so we have to intsall or configure both.

For EPEL:-

#yum install https://dl.fedoraproject.org/pub/epel/epel-release- latest-8.noarch.rpm

installing epel

For REMI-

#yum install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

installing remi

Now installing php7.4 as -

#dnf module install php:remi-7.4

Installing php-mysqlnd as it is native driver of MySQL for php-

#dnf install php-mysqlnd

Now the most important step to download the wordpress application with the help of wget command installed previously with the help of command:-

#wget https://wordpress.org/latest.tar.gz

downloading tar file

After downloading this tar file to be unpacked and store its content in the root directory of httpd package that is /var/www/html this can be done as

#tar xf latest.tar.gz -C /var/www/html

unpacking and moving files

In the above image it can be seen the files successfully moved to the directory.

Httpd can’t write to folder/file because of SELinux so allow it & use the commands:-

#setenforce 0

#chcon -t httpd_sys_rw_content_t /var/www/html/wordpress -R

Start the services of httpd:-

#systemctl start httpd

services of httpd

Testing the web site-

Hit the url- <public_ip_instance>/wordpress

Hurray! successfully launched.

Now for proper connection provide the details . Here we use same database initially created and in the host field provide the endpoint given by AWS.

In my case the wordpress was not able to create wp-config.php file so I have to create manually in the same root directory and copy the content provided and then hit on run installation button.

creation of account
account successfully created

After creation of account log in back to the wordpress

The Final outcome

Cross verifying the database

For verifying the successful database creation there is need to login into the database and it can be done with the password authentication with the credentials set initially.

Command to install mysql:-

#yum install mysql

installing mysql

Now for login into the database the following command can be used:-

#mysql -h [endpoint url] -u [username] -p

login into database

Now for viewing different databases use #show databases;

using a particular database #use [dbname] is used.

And to see the tables in a paricular database the command used as:-

#show tables;

Hence, the database is created and objective is successfully achieved.

learning more and sharing more

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store