Deploy Wordpress Website on AWS

Deploy Wordpress Website on AWS

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-01

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

Step 1: Create an RDS Database: Create an RDS Database just like we created on Day 44: RDS set-up day 44

Step 2: Create an EC2 Instance

Step 3: Configure your Amazon RDS Database

Edit the inbound rules to change the rules for your security group. 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. Choose the wordpress security group that you used for your EC2 instance.

Connect to EC2 instance using SSH

Run the following command in your terminal to install a MySQL client:

sudo apt update -y && sudo apt install mysql-client -y

Login to the database server using the below command:

mysql -h <endpoint> -P 3306 -u admin -p

Create a database and user with the following command:

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

We need to install Apache on our instance to run a web server

sudo apt-get install apache2 -y

Go to your instance, click on it copy the Public IPv4 address and open it in your web browser.

Download and configure wordpress on the instance

 wget https://wordpress.org/latest.tar.gz 
 tar -xzf latest.tar.gz
# you can run ls to view the contents of the directory

Change the directory to the WordPress directory and make a copy of the cp wp-config-sample.php with the below command:

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

DB_NAME: “wordpress”
DB_USER: The name of the user you created in the database 
DB_PASSWORD: The password for the user you created for the database
DB_HOST: The hostname of the database that you created

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

The values for this configuration can be found here

Now, we will install the application dependencies we need for WordPress

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

Then, we will copy the file contents from the WordPress folder to the /var/www/html folder to configure the application with the Apache web server.

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

Restart the Apache web server.

sudo systemctl restart apache2

Then, we will navigate to the public-IP/wp-admin/

Thank you.