Day 45: Deploy WordPress website on AWS 🚀🔥

Day 45: Deploy WordPress website on AWS 🚀🔥

Introduction: Welcome back to our journey of building and deploying a website! Today, on Day 45, we're diving into the exciting realm of deploying a WordPress website on Amazon Web Services (AWS). WordPress is one of the most popular content management systems, and AWS offers robust infrastructure for hosting dynamic web applications. By combining these two, we can create a scalable and reliable platform for our website.

Setting Up AWS: Before we start deploying our WordPress site, let's ensure we have an AWS account set up. If you don't have one yet, head over to the AWS website and create an account. Once you're logged in, let's navigate to the AWS Management Console to get started.

Launching an EC2 Instance: Our first step is to launch an EC2 (Elastic Compute Cloud) instance, which will serve as the server for our WordPress site.

  1. Log in to the AWS Management Console.

  2. Navigate to the EC2 dashboard.

  3. Click on the "Launch Instance" button.

  4. Choose an Amazon Machine Image (AMI) - select a WordPress AMI from the AWS Marketplace.

  5. Select an instance type based on your requirements.

  6. Configure instance details such as network settings, storage, and tags.

  7. Configure security groups to allow HTTP and HTTPS traffic.

  8. Review and launch the instance.

Setting Up WordPress: Once our EC2 instance is up and running, we'll proceed with setting up WordPress on it.

  1. Connect to your EC2 instance using SSH (Secure Shell).

  2. Install LAMP (Linux, Apache, MySQL, PHP) stack on your instance.

  3. Download and install WordPress.

  4. Configure Apache to serve your WordPress site.

  5. Create a MySQL database and user for WordPress.

  6. Configure WordPress to use the MySQL database.

  7. Complete the WordPress installation by accessing your server's public IP address in a web browser.

Securing Your WordPress Installation: Security is paramount when deploying a website. Here are some essential steps to secure your WordPress installation on AWS:

  1. Update WordPress, themes, and plugins regularly.

  2. Configure proper file permissions.

  3. Enable HTTPS using SSL/TLS certificates.

  4. Limit access to wp-admin and sensitive files.

  5. Implement strong passwords and enable two-factor authentication.

  6. Install security plugins like Wordfence or Sucuri.

Scaling and High Availability: AWS offers scalability and high availability features that allow your WordPress site to handle increased traffic and maintain uptime. Here are some strategies to scale and ensure high availability:

  1. Utilize AWS Auto Scaling to automatically adjust the number of EC2 instances based on traffic.

  2. Implement a Content Delivery Network (CDN) like Amazon CloudFront to cache static content and reduce latency.

  3. Set up Amazon RDS (Relational Database Service) for managed MySQL databases to improve database performance and reliability.

  4. Configure Amazon Route 53 for DNS management and failover routing to distribute traffic across multiple regions.

WordPress serves as the content management system (CMS) for more than 30% of all websites on the internet. It may be used to manage e-commerce sites, discussion boards, and many other well-known things, but blogs are where it is most frequently utilized. You may learn how to set up a WordPress blog site by reading this guide.

Task-01

As WordPress requires a MySQL database to store its data, create an RDS as you did on Day 44

Visit the Amazon RDS interface. the "Create database" button.

No alt text provided for this image

Make "MySQL" your engine type choice.

No alt text provided for this image

For the "Database instance class" template, select the "Free tier" option.

No alt text provided for this image

Give the "Database instance identification" a unique name.

Set the "Master username" and "Master password" for the database.

No alt text provided for this image

Configure the instance's "Virtual Private Cloud (VPC)" and "Subnet Group" settings. Maintain the default values for the other parameters.

No alt text provided for this image

No alt text provided for this image

Choose 'Default VPC'

No alt text provided for this image

No alt text provided for this image

Click on "create database"

No alt text provided for this image

The database was created.

No alt text provided for this image

To configure this WordPress site, you will create the following resources in AWS:

WordPress installation and hosting on an Amazon EC2 instance.

access the Amazon EC2 console. Choose a Linux AMI by clicking "Launch Instance."

Select a VPC and subnet, and then a kind of instance, such as t2.micro.

Set up security group rules so that incoming traffic is permitted on the correct port for the type of database you're using (e.g. port 3306 for MySQL).

No alt text provided for this image

An Amazon RDS for MySQL database to store your WordPress data.

Choose the MySQL database you just established, navigate to the Connectivity & Security tab, and select the VPC security group. You may access the security group set up for your database using the console.

No alt text provided for this image

To modify the rules for your security group, select the Incoming Rules tab and then the Edit inbound rules button.

By changing the Type attribute to MYSQL/Aurora, the Protocol and Port range will be updated to the correct settings.

The security group that you used for your EC2 instance should be selected.

No alt text provided for this image

Enter your EC2 instance via SSH.

No alt text provided for this image

Install a MySQL client in your terminal to access the database by running the following command:

sudo apt install mysql-client-core-8.0

No alt text provided for this image

No alt text provided for this image

Use the following command to connect to your MySQL database in your terminal. Substitute your master username and password for "user" and "password," which you specified when you created your Amazon RDS database. The RDS database endpoint for -h is the host.

mysql -h <rds-database-endpoint> -P <port-no> -u <user> -p <password>

No alt text provided for this image

Create a database user for your WordPress application, and then grant access to the WordPress database to the user.

Enter the commands below into your terminal:

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

To protect your database, you ought to use a stronger password than WordPress-pass.

No alt text provided for this image

On your EC2 instance, you must operate a web server in order to run WordPress.

Run the following command in your terminal in order to install Apache on your EC2 instance:

sudo apt-get install apache2

No alt text provided for this image

In your terminal, type the following command to launch the Apache web server:

systemctl restart apache2

By accessing your ec2 instance's public IP, you may verify that your Apache web server is operational.

No alt text provided for this image

Set up the server and post your new WordPress app.

Use the following commands in your terminal to first download and uncompress the software:

wget https://wordpress.org/latest.tar.g
tar -xzf latest.tar.gzz

No alt text provided for this image

With the ls command, you will notice a tar file and a directory called WordPress that contains the uncompressed contents.

No alt text provided for this image

open the wp-config.php file

No alt text provided for this image

Modify the following lines in the database configuration:

No alt text provided for this image

  1. DB_NAME: your RDS database name

  2. DB_USER: The name of the user you created in the database in the previous steps

  3. DB_PASSWORD: The password for the user you created in the previous steps

  4. DB_HOST: The hostname of the database means your database endpoint

The Authentication Unique Keys and Salts configuration area is the second one that needs to be set up.

You can substitute the following text for everything in that section:

Make sure to create the following details with https://api.wordpress.org/secret-key/1.1/salt

define('AUTH_KEY',         'Z9-CmDhIDuNlO8t5EM[+xf-[`VJ)_A>qknjR>Kat$2a6=oYF_-|%H+4MkJW^!t9x');
define('SECURE_AUTH_KEY',  '(sIg&e-5bk|&=ruFb0LLF,P$&kFS_L+B]ovbC@wEN`@mE~V q?TWzMvz;v3ZGnF1');
define('LOGGED_IN_KEY',    'ZA(ia@)uP7i#Z.=$`jBZPv|IUW=6|;+xuTcPCYR+f.U[i((;nS,!?0z!ifYY$O=F');
define('NONCE_KEY',        'c3k|3LBocTe%J#-|Lnl%8eL,TD3,nV-AU|Y(M*|Vy:##dJT{KMNzDu*J7e9:xbX=');
define('AUTH_SALT',        '+mRr-[sDf-KsN&i;*qVjUkDV=A-n.&]G~oVH&J0M,taM,1>vkjjuOiQm6RIhUmmo');
define('SECURE_AUTH_SALT', 'dmOHiQah U<_Z+np}D>i=~0f[5hv509+E/8WNymuQ5P/-j#h&TO>tY5HHM$qG,Pt');
define('LOGGED_IN_SALT',   '=X|}omdoywp,j.1eq;z0dmK],|*s1FJ5kf<Q7+-qr jX/VgOub++FgBX8E,8<}r2');
define('NONCE_SALT',       '/dNw0(+[W.@-8|kXMppSKv0e1>@P_|b05y-GS^!Hb`!Xj0Z+L-VGm|? K9`krU/1');

No alt text provided for this image

Make sure you have replaced the text with the text you have created.

Installing WordPress application dependencies comes first. Activate the following command in your terminal.

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

No alt text provided for this image

Copy your WordPress application files into the /var/www/html directory used by Apache.

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

No alt text provided for this image

Finally, restart the Apache web server

systemctl restart apache2

The WordPress welcome page should be visible if you navigate to "ec2-public-ip/wp-admin/".

No alt text provided for this image

I appreciate you continuing to read; I hope you learned something. ❤️🙌