Day 45: Deploy WordPress website on AWS - 90DaysOfDevOps

Over 30% of all websites on the internet use WordPress as their content management system (CMS). It is most often used to run blogs, but it can also be used to run e-commerce sites, message boards, and many other popular things. This guide will show you how to set up a WordPress blog site.

Task -

  • 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.

Steps -

  1. Create an RDS MySQL database as we created on Day44 - Day44-RDS-Setup. Follow Documentation to create the database.

  2. Launch a new EC2 instance with port 3306 enabled for MYSQL.

  3. Go to the MySQL database you created and edit the Security Group.

  1. Edit the inbound rules and update the All traffic security group to MySQL/Aurora. Change the Type property to MYSQL/Aurora, which will update the Protocol and Port range to the proper values. Then, remove the current security group value configured for the Source. The console will show the available security groups that are configured. Choose the WordPress security group that you used for your EC2 instance.

  1. SSH to the EC2 instance and install MySQL Client using the below commands.
sudo apt update -y && sudo apt install mysql-client -y
ubuntu@ip-172-31-91-94:~$ mysql --version
mysql  Ver 8.0.34-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
mysql -h <endpoint> -P 3306 -u admin -p

  1. Once you're logged in to the MySQL client, create the below database
CREATE DATABASE wordpress;
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
Exit

  1. Now, to run a web server, we need to install Apache using the below command -
sudo apt-get install apache2 -y

  1. Validate if you can access the apache2 default page using EC2 public IP (Open port 80 if the page is not accessible).

  1. Go back to SSH and download and configure WordPress.
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cd wordpress
cp wp-config-sample.php wp-config.php

  1. Edit the file wp-config.php and update the below entries with your configuration values.
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'wordpress' );

/** Database password */
define( 'DB_PASSWORD', 'wordpress1' );

/** Database hostname */
define( 'DB_HOST', 'wordpress.cf2bhn2hoqgz.us-east-1.rds.amazonaws.com' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
  1. Update the below entries with random values, you can get the values from Here

  1. Now, install the dependencies and copy the WordPress files to /var/www/html/ path to run the webpage.

  2. Install the apache2 service.

sudo apt install php libapache2-mod-php php-mysql -y
sudo cp -r wordpress/* /var/www/html/
sudo systemctl restart apache2
  1. Access the public IP and you should be able to access the WordPress webpage with database connectivity. -

Detailed Documentation - Deploy WordPress with Amazon RDS GUIDE

Thank you :)