Day 32: Deployment of a WordPress website on AWS

Day 32: Deployment of a WordPress website on AWS

Table of contents

Hello Everyone!

Yesterday in the last article we saw the deployment of an RDS database in AWS. Today let's explore more and deploy a Wordpress website on an RDS with the help of an EC2 instance.

What is WordPress?

WordPress is a website builder and content management system. It is an open source software that anyone can use to make any kind of website imaginable.

Founded by Matt Mullenweg and Mike Little in 2003, it was a fork of an existing blogging tool called ‘b2/cafelog’.

WordPress soon transformed into a CMS and later a full-fledged website-building platform. According to our WordPress market share report, it powers more than 43% of all websites on the internet.

Tasks

Task 1) As WordPress requires a MySQL database to store its data, create an RDS as you did on Day 44. To configure this WordPress site, you will create the following resources in AWS:
- An Amazon EC2 instance to install and host the WordPress application.
- An Amazon RDS for MySQL database to store your WordPress data.
- Set up the server and post your new WordPress app.

  • Create RDS

  • Go to AWS Management Console > Search and Select RDS > Click on Create Database

  • Scroll down to Additional Configuration after the Monitoring section:

    Initial Database name: WordPress-db and retain the default settings.

  • Click on Create Database: After a few minutes, you can observe that the RDS is created.

    Step 2) Create EC2 Instance

  • Now Create a EC2 Instance

Step 3) Configure the Amazon RDS Database

Services Used: Amazon RDS

Modify your Amazon RDS database to allow network access from your EC2 instance.

In the RDS Console > Select and open the Database you created.

Scroll to Connectivity and Security, and select the VPC Security Group

In the Security Groups > Go to Inbound Rules > Edit Inbound Rules.

For the existing rule > Change type to MySQL/Aurora > Remove the Security group configured earlier and select the Security group which you created earlier named wordpress-SG.

And click on Save Rules.

Now connect to your EC2 instance using SSH.

Let us create a Database user.

Install MySQL on your instance. Since in my OS, there are no default package repositories, let’s install the MySQL client by adding the MySQL Community Repository to your system and then installing the client from there:

sudo apt-get update
sudo apt-get install mysql-client -y
mysql --version

Here, We can see we’ve successfully installed mysql on our ec2 instance.

Run the following command in your terminal to connect to your MySQL database:

Go to RDS Console > Open the Database you created > In the details of your Amazon RDS database, the hostname will be shown as the Endpoint in the Connectivity & Security section.

In the command line, use the following command:

export MYSQL_HOST=<your-endpoint>

Run the following command in your terminal to connect to your MySQL database:

mysql --user=<user> --password=<password> wordpress

Run the following commands to create the user:

CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
Exit

Step 4 ) Configure WordPress on EC2

Services Used: EC2

Install the Apache Server:

sudo apt update
sudo apt install apache2

Go to your EC2 instance Page > Copy the Public DNS > Open this in the Browser:

Now let us Download and Configure WordPress.

To download and uncompress the software WordPress:

wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz

To change the directory to the WordPress directory and create a copy of the default config file

cd wordpress
cp wp-config-sample.php wp-config.php

Let us edit the wp-config.php using:

vim wp-config.php

The values that should be replaced are:

  • DB_NAME: “wordpress”

  • DB_USER: The name of the user you created in the database in the previous module

  • DB_PASSWORD: The password for the user you created in the previous module

  • DB_HOST: The hostname of the database that you found in the previous module

The changed lines would look like:

  1. Authentication Unique Keys and Salts:

You can generate the content of this section from this link: https://api.wordpress.org/secret-key/1.1/salt/.

Replace with the existing content.

Save and exit the file.

Let us deploy the WordPress now.

We need some dependencies for WordPress to function properly:

sudo apt install php libapache2-mod-php php-mysql -y

The above command will install PHP, the Apache module for PHP, and the PHP MySQL extension on your Ubuntu system.

Go to the proper directory and copy your WordPress application files into the /var/www/html directory used by Apache:

cd ..
sudo cp -r wordpress/* /var/www/html/

Let us restart our Apache server to incorporate the changes we made:

sudo systemctl restart apache2

Go to your Apache Web server and you should see the WordPress welcome page and the five-minute installation process.

In your Web Browser, give the address of your website in the following format to access the server:

http://Public_IPv4/wp-admin

You should be able to see the following page:

Yay!! We’ve configured our wordpress page.


Thanks for reading;)